简体   繁体   English

iPhone:获取相机预览

[英]iPhone: Get camera preview

I'd like to get the image that is being displayed on the UIImagePickerController when user uses the camera. 我想获取用户使用相机时正在UIImagePickerController上显示的图像。 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. 但是问题是当我想获取摄像机视图时,图像只是一个黑色矩形。

Here's my code: 这是我的代码:

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

What am I doing wrong? 我究竟做错了什么?

Thanks. 谢谢。

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? 我仍未找到解决方案的问题是,如何在没有任何覆盖的情况下非常快速地获取相机图像?

The unofficial call is: 非正式的电话是:

UIGetScreenImage()

which you declare above the @implementation as: 您在@implementation上方声明为:

extern CGImageRef UIGetScreenImage();

There may be a documented way to do this in 3.1, but I'm not sure. 在3.1中可能有记录的方法可以执行此操作,但是我不确定。 If not, please please file a Radar with Apple asking them to make some kind of screen grab access public!!! 如果不是,请向Apple提交Radar ,要求他们公开某种屏幕抓取访问权限!!!

That uses your same AppleID you log in to the iPhone development portal with. 它使用您登录iPhone开发门户时使用的相同AppleID。

Update: This call is not yet documented, but Apple explicitly has given the OK to use it with App Store apps. 更新:此调用尚未记录,但Apple明确表示可以将其与App Store应用程序一起使用。

at least for now, there's no way to do this. 至少到目前为止,还没有办法做到这一点。 (certainly no official documented way, and as far as I know nobody's figured out an unofficial way either.) (肯定没有官方记录的方式,据我所知,也没有人想出非官方的方式。)

the camera preview data is being drawn by the OS in some way that bypasses the normal graphics methods. 操作系统正在以某种方式绕过常规图形方法绘制摄像机预览数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM