Skip to content

Instantly share code, notes, and snippets.

@zld
Created June 12, 2015 04:22
Show Gist options
  • Save zld/a69cfdb9a6197736b26b to your computer and use it in GitHub Desktop.
Save zld/a69cfdb9a6197736b26b to your computer and use it in GitHub Desktop.
UIImage *image = ...;
//Have the image draw itself in the correct orientation if necessary
if(!(image.imageOrientation == UIImageOrientationUp ||
image.imageOrientation == UIImageOrientationUpMirrored))
{
CGSize imgsize = image.size;
UIGraphicsBeginImageContext(imgsize);
[image drawInRect:CGRectMake(0.0, 0.0, imgsize.width, imgsize.height)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
NSData *png = UIImagePNGRepresentation(image);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment