3

当用户使用相机时,我想获取 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

我究竟做错了什么?

谢谢。

4

3 回答 3

7

这个也很好用。当相机预览打开时使用它:

UIImage *viewImage = [[(id)objc_getClass("PLCameraController") 
                      performSelector:@selector(sharedInstance)] 
                      performSelector:@selector(_createPreviewImage)];

但据我发现,它带来的结果与以下解决方案相同,后者对当前屏幕进行“截图”:

extern CGImageRef UIGetScreenImage();

CGImageRef cgoriginal = UIGetScreenImage();
CGImageRef cgimg = CGImageCreateWithImageInRect(cgoriginal, rect);            
UIImage *viewImage = [UIImage imageWithCGImage:cgimg];    
CGImageRelease(cgoriginal);                
CGImageRelease(cgimg);  

我还没有找到解决办法的一个问题是,如何在没有任何叠加的情况下快速获得相机图像?

于 2009-10-07T16:09:20.200 回答
1

非正式的电话是:

UIGetScreenImage()

您在@implementation 上方声明为:

extern CGImageRef UIGetScreenImage();

在 3.1 中可能有记录的方法可以做到这一点,但我不确定。如果没有,请向 Apple 提交Radar,要求他们公开某种屏幕抓取访问权限!!!

这使用您登录 iPhone 开发门户时使用的相同 AppleID。

更新:此调用尚未记录,但 Apple 明确允许将其与 App Store 应用程序一起使用。

于 2009-08-24T03:38:36.413 回答
0

至少目前,没有办法做到这一点。(当然没有官方记录的方式,据我所知,也没有人想出非官方的方式。)

操作系统正在以某种绕过正常图形方法的方式绘制相机预览数据。

于 2009-08-23T15:07:32.197 回答