0
我在可可應用程序中將此代碼調整爲某個尺寸的PNG文件,但我希望格式仍然是PNG,但沒有PNGRepresentation方法NSImage中。 我該怎麼做?在可可dev中將圖像從PNG格式調整爲PNG格式
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];