Last active
August 29, 2015 13:57
-
-
Save carlossless/9579889 to your computer and use it in GitHub Desktop.
Create PNG Animation Frame Images by Animating an UIImageView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)makeRotatedImagesWithImageView:(UIImageView *)imageView | |
{ | |
for (int i = 0; i < 30; i++) { | |
CGFloat angle = M_PI / 15 * i; | |
CGSize boundingSize = imageView.image.size; | |
boundingSize.width *= 2; | |
boundingSize.height *= 2; | |
UIGraphicsBeginImageContext(boundingSize); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGAffineTransform transform = CGAffineTransformIdentity; | |
transform = CGAffineTransformTranslate(transform, imageView.image.size.width, imageView.image.size.height); | |
transform = CGAffineTransformRotate(transform, angle); | |
transform = CGAffineTransformScale(transform, 1.0, -1.0); | |
CGContextConcatCTM(context, transform); | |
// Draw the image into the context | |
CGContextDrawImage(context, CGRectMake(-imageView.image.size.width, -imageView.image.size.height, imageView.image.size.width * 2, imageView.image.size.height * 2), imageView.image.CGImage); | |
// Get an image from the context | |
UIImage *rotatedImage = [UIImage imageWithCGImage: CGBitmapContextCreateImage(context)]; | |
// Create path. | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"menu-sync-icon-%[email protected]", i]]; | |
// Save image. | |
[UIImagePNGRepresentation(rotatedImage) writeToFile:filePath atomically:YES]; | |
// Clean up | |
UIGraphicsEndImageContext(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment