Posted by
Rasband, Wayne (NIH/NIMH) [E] on
Dec 28, 2010; 4:41pm
URL: http://imagej.273.s1.nabble.com/Manage-PNG-Transparency-with-ImageJ-tp3685645p3685650.html
On Dec 28, 2010, at 4:19 AM, Charles Flond wrote:
> Hello Wayne,
>
> Thanks for your feedback. Is there a reason why PNG transparency is only
> supported for 8-bit images ? Is it possible and / or plan to support
> transparency for 16 / 32 bit images?
ImageJ ignores the alpha values in ARGB images so what you need to do is set the alpha values, create an ARGB BufferedImage from the int[] pixel array, and then write the BufferedImage as a PNG using
ImageIO.write(bufferedImage, "png", new File(path));
You can't use ImagePlus.getBufferedImage() because it returns an RGB BufferedImage.
-wayne
> On Mon, Dec 27, 2010 at 10:49 PM, Rasband, Wayne (NIH/NIMH) [E] <
>
[hidden email]> wrote:
>
>> On Dec 27, 2010, at 12:06 PM, Charles Flond wrote:
>>
>>> Hi All,
>>>
>>> Does anybody know how to manage PNG files with transparency using ImageJ
>> ? I
>>> tried to use the function writeImageWithTransparency(ImagePlus imp,
>> String
>>> path, int transparentIndex) but it doesn't seem to work.
>>>
>>> See
http://rsb.info.nih.gov/ij/source/ij/plugin/PNG_Writer.java for more
>>> details about this function.
>>>
>>> Any suggestions would be welcomed ! Thanks in advance.
>>
>> Plugins and scripts can save an 8-bit image as a PNG with transparency
>> using
>>
>> imp = IJ.getImage();
>> Prefs.setTransparentIndex(index);
>> IJ.saveAs(imp, "PNG", file_path);
>>
>> where 0<=index<=255. Macros can use
>>
>> call("ij.Prefs.setTransparentIndex", index);
>> saveAs("PNG", file_path);
>>
>> ImageJ does not support display with transparency so you will need to open
>> the saved PNG in another application (e.g., a Web browser) to verify that
>> the pixels with a value of 'index' are transparent. Note that PNG and GIF
>> transparency only works with 8-bit images.
>>
>> -wayne
>>