Skip to content

Instantly share code, notes, and snippets.

View jjxtra's full-sized avatar

Jeff Johnson jjxtra

View GitHub Profile
@jjxtra
jjxtra / imageRotated.m
Last active August 11, 2016 19:37
Rotating UIImage from AVCaptureSession [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:]
// this method rotates the UIImage captured by the capture session manager based on the device orientation when the image was captured ([AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];)
- (UIImage*) imageRotated:(UIImage*)image position:(AVCaptureDevicePosition)position orientation:(AVCaptureVideoOrientation)orientation
{
CGAffineTransform transform = CGAffineTransformIdentity;
CGFloat w = image.size.width * image.scale;
CGFloat h = image.size.height * image.scale;
CGFloat dw = w;
CGFloat dh = h;
image = [UIImage imageWithCGImage:image.CGImage scale:1.0f orientation:UIImageOrientationUp];