iPhone:获取相机预览 [英] iPhone: Get camera preview

查看:180
本文介绍了iPhone:获取相机预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户使用相机时,我想获取在UIImagePickerController上显示的图像。当我得到我想要处理的图像和显示,而不是常规的相机视图。

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.

这是我的代码:

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

我做错了什么?

谢谢。

推荐答案

这个工作相当不错。在相机预览打开时使用它:

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?

这篇关于iPhone:获取相机预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆