Preserve alpha/transparency when converting 32-bit PNG to BMP [Solved]

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: XnTriq, xnview

Defenestration
Posts: 52
Joined: Fri Aug 18, 2006 7:08 pm

Preserve alpha/transparency when converting 32-bit PNG to BMP [Solved]

Post by Defenestration »

I want to convert a load of images in different formats (some with tranparency/alpha channels) to a single format whilst preserving the alpha/transparency. I chose BMP as the target format (but may change to PNG in the future).

As a simple test in using NConvert to do this, I have a 32-bit PNG image which I wish to convert to BMP whilst preserving alpha/transparency. I tried the following, but when the BMP file is viewed the transparent area is no longer transparent. I would expect the following to work, but it doesn't:

Code: Select all

nconvert.exe -out bmp 32bit_png_image_with_alpha_transparency.png
I noticed that it does work when converting it to webp format though:

Code: Select all

nconvert.exe -out webp  32bit_png_image_with_alpha_transparency.png
How can I make it work when converting to BMP ?

Same goes for when converting image to PNG, also whilst keeping alpha/transparency.

Ideally, I want one command which works for all input image files of different formats.

I was expecting this to be easy with NConvert, but either it's buggy, or I'm not using the correct command-line options.
cday
XnThusiast
Posts: 3073
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Preserve alpha/transparency when converting 32-bit PNG to BMP

Post by cday »

While waiting for a possible response from Pierre or the forum transparency expert XnTriq, you might try including the following term in your code:

Code: Select all

-32bits           : Convert in 32bits
I am no transparency expert but believe that an equivalent operation is currently required in the GUI versions of xnview software.

If you are ultimately unable to use a single code line for any source file format, using two or if necessary more lines in a batch file shouldn't be a significant hardship, should it?
Defenestration
Posts: 52
Joined: Fri Aug 18, 2006 7:08 pm

Re: Preserve alpha/transparency when converting 32-bit PNG to BMP

Post by Defenestration »

-32bits option doesn't work.

I'm amazed that this relatively simple feature is still not supported (and not just in XnView, but also in some other Image viewers), despite PNG and BMP being two popular formats. There are lots of other options for controlling what you want to happen during the conversion, but a simple conversion (with or without transparency) to another format should just do the obvious - ie. if source has transparency and dest support it, dest should end up with it, and look the same. If dest doesn't support transparency, then convert without transparency.

Using multiple commands to achieve this is no problem, if someone can show me the commands ?

But, it should be possible to just do the following, and get the expected result (ie. 32 bit BMP image with same transparency/alpha channel), as is the case when dest is WebP format:

Code: Select all

nconvert.exe -out bmp 32bit_png_image_with_alpha_transparency.png
Please can you implement this feature in both NConvert/XnConvert and XnView/XnView MP.
User avatar
xnview
Author of XnView
Posts: 36386
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: Preserve alpha/transparency when converting 32-bit PNG to BMP

Post by xnview »

could you post the output bmp?
Pierre.
Defenestration
Posts: 52
Joined: Fri Aug 18, 2006 7:08 pm

Re: Preserve alpha/transparency when converting 32-bit PNG to BMP

Post by Defenestration »

Thanks for looking into this...

Source PNG:
32bit_png_image_with_alpha_transparency.png
Converted to following BMP:
32bit_png_image_with_alpha_transparency_converted_to_bmp.bmp
...using following options. Transparent bit is white in converted BMP.

Code: Select all

nconvert.exe -out bmp 32bit_png_image_with_alpha_transparency.png
You do not have the required permissions to view the files attached to this post.
User avatar
xnview
Author of XnView
Posts: 36386
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: Preserve alpha/transparency when converting 32-bit PNG to BMP

Post by xnview »

the BMP file is 32bits RGBA
Pierre.
Defenestration
Posts: 52
Joined: Fri Aug 18, 2006 7:08 pm

Re: Preserve alpha/transparency when converting 32-bit PNG to BMP

Post by Defenestration »

Why is the part of the image surrounding the ball transparent in the PNG, but white in the BMP ?

How can I get the white bit to be transparent ?

Why doesn't NConvert convert it whilst preserving the transparent part (ie. so it looks just like the PNG source) ?
User avatar
xnview
Author of XnView
Posts: 36386
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: Preserve alpha/transparency when converting 32-bit PNG to BMP

Post by xnview »

Defenestration wrote: Fri Oct 22, 2021 8:11 pm Why is the part of the image surrounding the ball transparent in the PNG, but white in the BMP ?

How can I get the white bit to be transparent ?

Why doesn't NConvert convert it whilst preserving the transparent part (ie. so it looks just like the PNG source) ?
the alpha is preserved, many viewers don't support 32bits BMP, please check with XnView
Pierre.
Defenestration
Posts: 52
Joined: Fri Aug 18, 2006 7:08 pm

Re: Preserve alpha/transparency when converting 32-bit PNG to BMP

Post by Defenestration »

You are right, Pierre.

Apologies for not testing properly, and jumping to conclusions.

This is a real plus for XnView/XnConvert, as most other apps do not handle this.