Hi everyone,
I'm trying to write an app that uses images retrieved from the UIImagePickerController. These images may be fairly large. I would like to manipulate them and then be able to save them back to the photo album with UIImageWriteToSavedPhotosAlbum. My problem is that when I run the following code on a photo taken in portrait mode, the resulting saved image comes out sideways and distorted. If the source image is landscape, the resulting saved image is perfect. What am I missing here?
Code:
// let's assume workImage is a UIImageView that has an image loaded in it
int w = workImage.image.size.width;
int h = workImage.image.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
// draw the Master image on the context
CGContextDrawImage(context, CGRectMake(0, 0, w, h), workImage.image.CGImage);
// do other manipulation/drawing to the context here
// ...
// ...
// Create the image to save
CGImageRef imageRef = CGBitmapContextCreateImage(context);
UIImage *saveImage = [[UIImage alloc] initWithCGImage:imageRef];
// close up the context
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
// save the image
UIImageWriteToSavedPhotosAlbum(saveImage, nil, nil, nil);
// release the saveImage
[saveImage release];
One more thing, I checked out the imageOrientation of the returned image and it's always UIImageOrientationUp in both cases.