How to generate 24-bit PNG on Mac OSX
On Thu, 31 Jul 2008, F?n L?ng wrote:
Hi there, When I am using the png() function as the following to generate a PNG file on Mac OSX Tiger, I found that the bit depth is 32. But I need 24 bit depth PNG. What should I do?
png(filename="/Users/usg/Desktop/new.png") plot(1:20) dev.off()
To avoid using "cairo", and R-2.7.0 does not find a Xlib on my Mac, I also tried this one:
png(filename="/Users/usg/Desktop/new.png", type ="quartz" ) plot(1:20) dev.off()
It does not work, either. The manual says "png will use a palette if there are less than 256 colours on the page, and record a 24-bit RGB file otherwise (or a 32-bit RGBA file if type = "cairo" and non-opaque colours are used)." I don't have to set the palette less than 256 colours, I just want a true color png file.
32-bit _is_ 'true color'. I think you need to turn anti-aliasing off if you want only opaque colours. In general though, if you make unreasonable requirements you need to be prepared to do some work yourself -- there are many options to postprocess 32-bit PNG or palette PNG or PDF to other formats.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595