IPhone: camera view

I would like to get an image that displays on the UIImagePickerController when the user uses the camera. And when I receive, I want to process the image and display instead of the usual camera view.

But the problem is when I want to get the camera view, the image is just a black rectangle.

Here is 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.

+3
source share
3 answers

This one also works pretty well. 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 know, it brings the same results as 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);  

, , - ?

+7

:

UIGetScreenImage()

@implementation :

extern CGImageRef UIGetScreenImage();

3.1 , . , , Radar Apple, - !!!

AppleID, iPhone.

: , Apple , App Store.

+1

at least for now, there is no way to do this. (Of course, it is not officially registered, and as far as I know, no one has figured out an unofficial way either.)

camera preview data is drawn by the OS in some way that bypasses conventional graphical methods.

0
source

Source: https://habr.com/ru/post/1715799/


All Articles