Ily*_*ski 3 iphone camera cocoa-touch uiimagepickercontroller
我想在用户使用相机时获取UIImagePickerController上显示的图像.当我得到我想要处理图像和显示而不是常规的相机视图.
但问题是当我想要获取相机视图时,图像只是一个黑色矩形.
这是我的代码:
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
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
谢谢.
这个也很好用.打开相机预览时使用它:
UIImage *viewImage = [[(id)objc_getClass("PLCameraController")
performSelector:@selector(sharedInstance)]
performSelector:@selector(_createPreviewImage)];
Run Code Online (Sandbox Code Playgroud)
但据我所知,它带来的结果与以下采用当前屏幕截图的解决方案相同:
extern CGImageRef UIGetScreenImage();
CGImageRef cgoriginal = UIGetScreenImage();
CGImageRef cgimg = CGImageCreateWithImageInRect(cgoriginal, rect);
UIImage *viewImage = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgoriginal);
CGImageRelease(cgimg);
Run Code Online (Sandbox Code Playgroud)
我还没有找到修复的问题是,如何在没有任何叠加的情况下快速获得相机图像?