iPhone:获取相机预览
我想获取当用户使用相机时 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个也运行得很好。在相机预览打开时使用它:
但据我发现,它带来的结果与以下获取当前屏幕“屏幕截图”的解决方案相同:
我仍然没有找到解决方案的一个问题是,如何能否在没有任何叠加的情况下快速获取相机图像?
This one is also working quite good. Use it when the camera preview is open:
But as far as I found out it brings the same results than the following solution which takes a 'screenshot' of the current screen:
A problem I didn't still find a fix for is, how can one get the camera image very fast without any overlays?
非官方的调用是:
您在 @implementation 上方声明为:
3.1 中可能有记录的方法可以执行此操作,但我不确定。如果没有,请向 Apple 提交 Radar 要求他们制作某种屏幕抓取访问公共!!!
它使用您登录 iPhone 开发门户时使用的相同 AppleID。
更新:此调用尚未记录,但 Apple 已明确同意将其与 App Store 应用程序一起使用。
The unofficial call is:
which you declare above the @implementation as:
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.
至少目前来说,还没有办法做到这一点。 (当然没有官方记录的方式,据我所知,也没有人找到非官方的方式。)
相机预览数据是由操作系统以某种绕过正常图形方法的方式绘制的。
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.