How do I create an 8-bit PNG with transparency from an NSBitmapImageRep?
Posted
by Rob Keniger
on Stack Overflow
See other posts from Stack Overflow
or by Rob Keniger
Published on 2010-03-03T04:11:02Z
Indexed on
2010/03/08
1:49 UTC
Read the original article
Hit count: 353
I have a 32-bit NSBitmapImageRep
which has an alpha channel with essentially 1-bit values (the pixels are either on or off).
I want to save this bitmap to an 8-bit PNG file with transparency. If I use the -representationUsingType:properties:
method of NSBitmapImageRep
and pass in NSPNGFileType
, a 32-bit PNG is created, which is not what I want.
I know that 8-bit PNGs can be read, they open in Preview with no problems, but is it possible to write this type of PNG file using any built-in Mac OS X APIs? I'm happy to drop down to Core Image or even QuickTime if necessary. A cursory examination of the CGImage
docs didn't reveal anything obvious.
EDIT:
I've started a bounty on this question, if someone can provide working source code that takes a 32-bit NSBitmapImageRep
and writes a 256-color PNG with 1-bit transparency, it's yours.
© Stack Overflow or respective owner