Creating a Transparent PNG with Alpha Channel
QUESTION: According to the IDL documentation, I can only create a transparent PNG file by using a 2D image and color table vectors. But I have a true-color image and an alpha channel. Is the IDL documentation correct?
ANSWER: No, it is incorrect. If you pass Write_PNG an image that is 4-by-cols-by-rows then that image will be written correctly as a alpha channel image. The alpha channel (the fourth “frame”) in the image should contain byte values between 0 and 255. A value of zero indicates that the pixel at that location is completely opaque and a value of 255 indicates that the pixel at that location is completely transparent. Intermediate values indicate intermediate values of opacity. Note that pixel interleaving (the 4 is in the first dimension of the image) is required. The TRANSPARENT keyword does not have to be used when creating a transparent image with an alpha channel.
IDL> Help, image IMAGE BYTE = Array[4, 162, 150] IDL> Write_PNG, 'example.png', image
Version of IDL used to prepare this article: IDL 7.1.
Copyright © 2009 David W. Fanning
Last Updated 25 October 2009