Skip to content

Instantly share code, notes, and snippets.

@jgv
Created June 21, 2012 22:15
Show Gist options
  • Save jgv/2968919 to your computer and use it in GitHub Desktop.
Save jgv/2968919 to your computer and use it in GitHub Desktop.
my save method
- (void)save {
UIImage *bgImage = editView.image;
//UIImage *fgImage = yoloView.image;
// a rect that has has the transformation from the yoloview applied to it
CGRect rect = CGRectApplyAffineTransform([yoloView frame], [yoloView transform]);
// the rect we are manipulating
//CGRect rect = CGRectMake(0, 0, yoloView.size.width, yoloView.image.size.height);
// begin rendering context
UIGraphicsBeginImageContextWithOptions(bgImage.size, FALSE, 0.0);
// first draw background image
[bgImage drawInRect:CGRectMake( 0, 0, bgImage.size.width, bgImage.size.height)];
// the current context
CGContextRef ctx = UIGraphicsGetCurrentContext();
// Clear the context
CGContextClearRect(ctx, rect);
// Transform the image (as the image view has been transformed)
CGContextConcatCTM(ctx, yoloView.transform);
// translate for different coordinate systems
CGContextTranslateCTM(ctx, rect.size.width * 1.5, rect.size.height * 1.5);
// CGContextTranslateCTM(ctx, -rect.size.width * 1.5, -rect.size.height * 1.5);
// Translate and scale upside-down to compensate for Quartz's inverted coordinate system
CGContextTranslateCTM(ctx, 0.0, rect.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
// to maintain scale
CGContextScaleCTM(ctx, 4, 4);
// draw the bitmap
CGContextDrawImage(ctx, rect, yoloView.image.CGImage);
// save the instance of an image
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); // end the drawing
UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil); // save the image
NSLog(@"saved");
}
@jgv
Copy link
Author

jgv commented Jun 21, 2012

  • Line 21: because im using an iphone 4s and it has a retina display. Or is it a coordinate system thing
  • Line 16: Multiplying by 1.5 is close, but still off by a little

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment