我有一个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秒的间隙,所以它看起来很奇怪。在使用自定义叠加层时,我已经看到应用程序立即从按相机切换到最终视图。
有人遇到过这个吗?
答案 0 :(得分:1)
获取即时图像的方法是首先使用屏幕截图并使用该图像,然后调用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];
}