iPhone:获取相机预览
当用户使用相机时,我想获取在UIImagePickerController上显示的图像。当我得到我想要处理的图像和显示,而不是常规的相机视图。
I'd like to get the image that is being displayed on the UIImagePickerController when user uses the camera. And when I get I want to process the image and display instead of regular camera view.
但问题是当我想得到相机视图,图像只是
But the problem is when I want to get the camera view, the image is just a black rectangle.
这是我的代码:
UIView *cameraView = [[[[[[imagePicker.view subviews] objectAtIndex:0]
subviews] objectAtIndex: 0]
subviews] objectAtIndex: 0];
UIGraphicsBeginImageContext( CGSizeMake(320, 427) );
[cameraView.layer renderInContext: UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageToDisplay.image = [PixelProcessing processImage: viewImage]; //In this case the image is black
//imageToDisplay.image = viewImage; //In this case the image is black too
//imageToDisplay.image = [UIImage imageNamed: @"icon.png"]; //In this case image is being displayed properly
我做错了什么?
谢谢。
这个工作相当不错。在相机预览打开时使用它:
This one is also working quite good. Use it when the camera preview is open:
UIImage *viewImage = [[(id)objc_getClass("PLCameraController")
performSelector:@selector(sharedInstance)]
performSelector:@selector(_createPreviewImage)];
但是据我发现它带来的结果与下面的解决方案相同, '的当前屏幕:
But as far as I found out it brings the same results than the following solution which takes a 'screenshot' of the current screen:
extern CGImageRef UIGetScreenImage();
CGImageRef cgoriginal = UIGetScreenImage();
CGImageRef cgimg = CGImageCreateWithImageInRect(cgoriginal, rect);
UIImage *viewImage = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgoriginal);
CGImageRelease(cgimg);
一个问题我还没有找到一个修复是,快速没有任何叠加?
A problem I didn't still find a fix for is, how can one get the camera image very fast without any overlays?