I'm capturing an image from camera using AVCaptureSession:
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
The image gets converted into a UIImage and is added to an image view. The image is displayed in a portrait orientation, as expected.
I'm trying to save the image into core data between capture sessions. My core data entity has an image property with binary data type.
coreDataEntity.image = UIImagePNGRepresentation(imageView.image);
Once the user reloads a previously saved session, the image view has its image restored using:
imageView.image = [UIImage imageWithData:coreDataEntity.image];
However, the restored image is rotated 90 degrees counterclockwise with it's top pointing to the left.
At which point does the image get rotated? Is it during saving or during loading from core data?
I have a method to rotate a UIImage by 90 degrees, but it appears that on subsequent re-loading of the same image, it gets rotated by extra 90 degrees. How can I know that I've already rotated a UIImage once?
Thank you for any help!