我需要将像素编辑器应用程序的内容保存到 .png 文件中,但我无法找到完成此操作的最佳方法。像素数据存储在 32 位 RGBA 缓冲区中。谁能建议我可以用来完成此任务的任何好工具?
编辑:
不幸的是,cocotron 不支持 CGImage 和representationUsingType:,我也需要能够将我的应用程序定位到 PC 版本,有人可以建议第三种方法来完成此任务吗?
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];
如果你不能使用这些 Cocoa 方法,请查看libpng http://www.libpng.org/pub/png/pngcode.html.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)