我有一个带有自己的摄像头按钮的cameraOverlay,当他们按下摄像头按钮并使用委托方法时,我会使用takePicture
方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info{
[CommonClass AddToStack:@"ReviewController:imagePickerController"];
PhotoOverlay *overlay = (PhotoOverlay*)picker.cameraOverlayView;
[overlay setupImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
}
setupImage:
方法只是为叠加层上的UIImageView设置图像问题是
takePicture
和imagepicker委托方法之间有0.3秒的间隔,因此它看起来确实很奇怪。我已经看到,使用自定义叠加层时,应用程序会立即从按下相机过渡到最终视图。有人遇到过这个吗?
最佳答案
获取即时图像的方法是对屏幕进行截图并首先使用该图像,然后调用takePicture
并在其准备就绪时将其替换为截图(该截图的分辨率低于实际图像)。
这是我的片段:
-(void)CameraPressedTake
{
extern CGImageRef UIGetScreenImage();
PhotoOverlay *overlay = (PhotoOverlay*)cameraPicker.cameraOverlayView;
CGImageRef cgoriginal = UIGetScreenImage();
float width = 320.0;
float height = 480.0-[overlay myHeight];
//if it's retina...
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2) {
width = 2*width;
height = 2*height;
}
CGImageRef cgimg = CGImageCreateWithImageInRect(cgoriginal, CGRectMake(0, 0, width, height));
UIImage *viewImage = [UIImage imageWithCGImage:cgimg];
[overlay setupImage:viewImage];
CGImageRelease(cgoriginal);
CGImageRelease(cgimg);
[cameraPicker takePicture];
}