NSBitmapImageRep应该得到你需要的东西.将数据加载到其中NSBitmapImageRep
,然后使用representationUsingType:properties:它作为PNG将其输出.一个简单的例子:
NSBitmapImageRep *imageRep =
[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:imageBuffer
pixelsWide:imageWidth
pixelsHigh:imageHeight
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:NSAlphaFirstBitmapFormat
bytesPerRow:imageWidth * 4
bitsPerPixel:32];
NSData *pngData = [imageRep representationUsingType:NSPNGFileType
properties:propertyDictionary];
Run Code Online (Sandbox Code Playgroud)
如果你不能使用这些Cocoa方法,请查看libpng.