cgimage
Saving CGImageRef to a png file?
Using CGImageDestination and passing kUTTypePNG is the correct approach. Here’s a quick snippet: @import MobileCoreServices; // or `@import CoreServices;` on Mac @import ImageIO; BOOL CGImageWriteToFile(CGImageRef image, NSString *path) { CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path]; CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL); if (!destination) { NSLog(@”Failed to create CGImageDestination for %@”, path); return NO; } … Read more
Convert image to grayscale
I needed a version that preserved the alpha channel, so I modified the code posted by Dutchie432: @implementation UIImage (grayscale) typedef enum { ALPHA = 0, BLUE = 1, GREEN = 2, RED = 3 } PIXELS; – (UIImage *)convertToGrayscale { CGSize size = [self size]; int width = size.width; int height = size.height; // … Read more