iPhone:获取相机预览

发布于 2024-08-02 20:23:49 字数 865 浏览 2 评论 0原文

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

我做错了什么?

谢谢。

I'd like to get the image that is being displayed on the UIImagePickerController when user uses the camera. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苍白女子 2024-08-09 20:23:49

这个也运行得很好。在相机预览打开时使用它:

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);  

我仍然没有找到解决方案的一个问题是,如何能否在没有任何叠加的情况下快速获取相机图像?

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?

记忆で 2024-08-09 20:23:49

非官方的调用是:

UIGetScreenImage()

您在 @implementation 上方声明为:

extern CGImageRef UIGetScreenImage();

3.1 中可能有记录的方法可以执行此操作,但我不确定。如果没有,请向 Apple 提交 Radar 要求他们制作某种屏幕抓取访问公共!!!

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

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

The unofficial call is:

UIGetScreenImage()

which you declare above the @implementation as:

extern CGImageRef UIGetScreenImage();

There may be a documented way to do this in 3.1, but I'm not sure. If not, please please file a Radar with Apple asking them to make some kind of screen grab access public!!!

That uses your same AppleID you log in to the iPhone development portal with.

Update: This call is not yet documented, but Apple explicitly has given the OK to use it with App Store apps.

夏末的微笑 2024-08-09 20:23:49

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文