Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Created May 16, 2013 07:53
Show Gist options
  • Save odrobnik/5590114 to your computer and use it in GitHub Desktop.
Save odrobnik/5590114 to your computer and use it in GitHub Desktop.
Weird translation bug in this ...
// get source image
NSData *imageData = _picture.imageData;
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)(imageData), NULL);
CGImageRef sourceImage = CGImageSourceCreateImageAtIndex(source, 0, NULL);
CFRelease(source);
CGRect imageRect = CGRectZero;
imageRect.size.width = CGImageGetWidth(sourceImage);
imageRect.size.height = CGImageGetHeight(sourceImage);
imageRect.origin.x = -imageRect.size.width/2.0;
imageRect.origin.y = -imageRect.size.height/2.0;
// move origin to image center
CGContextTranslateCTM(context, outputSize.width/2.0, outputSize.height/2.0);
// apply image rotation
CGContextRotateCTM(context, -M_PI * _picture.editRotationDegrees/180.0);
// apply offset
CGContextTranslateCTM(context, _picture.editOffset.width, _picture.editOffset.height);
// apply image scale
CGContextScaleCTM(context, _picture.editScale, _picture.editScale);
// draw image
CGContextDrawImage(context, imageRect, sourceImage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment