I have an image that is being taken using AVCaptureSession and being returned to my view controller.
Here is a screen shot of the camera interface:
The AVCaptureSession takes the FULL SCREEN photo, and now I want to crop it down to the size of the visible window above.
The window will always be at the same location and the same size.
Height = 360 (180 non retina)px, Width = 640 (320 non retina)px, x = 0, y = 160.
How can I crop the image down to these coordinates so that the image itself is now 360 x 640?
Any help would be great, thanks!
This question is related to
ios
uiimage
crop
avcapturesession
You would need to do something like this. I am typing this off the top of my head, so this may not be 100% correct.
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(NULL, 640, 360, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedFirst); CGColorSpaceRelease(colorSpace); CGContextDrawImage(context, CGRectMake(0,-160,640,360), cgImgFromAVCaptureSession); CGImageRef image = CGBitmapContextCreateImage(context); UIImage* myCroppedImg = [UIImage imageWithCGImage:image]; CGContextRelease(context);
Source: Stackoverflow.com