I have this code in a cocoa application to resize a PNG file to a certain dimension but I want the format to be still a PNG, but there is no PNGRepresentation method for NSImage. How do I do this?
NSData *sourceData = [NSData dataWithContentsOfFile:fileName];
NSImage *sourceImage = [[NSImage alloc] initWithData: sourceData];
NSSize originalSize = [sourceImage size];
float resizeWidth = originalSize.width - 10;
float resizeHeight = originalSize.height - 10;
NSImage *resizedImage = [[NSImage alloc] initWithSize: NSMakeSize(resizeWidth, resizeHeight)];
[resizedImage lockFocus];
[sourceImage drawInRect: NSMakeRect(0, 0, resizeWidth, resizeHeight) fromRect: NSMakeRect(0, 0, originalSize.width, originalSize.height) operation: NSCompositeSourceOver fraction: 1.0];
[resizedImage unlockFocus];
NSData *resizedData = [resizedImage TIFFRepresentation];
[resizedData writeToFile:@"~/playground/resized.tif" atomically:YES];
[sourceImage release];
[resizedImage release];