Page 1 of 1

cant convert bmp to png

Posted: 2012-11-14T03:52:31-07:00
by ad34
Hello,

I have to convert via command line tool (convert.exe) bitmap generated in C++ to png

orignal bitmap are 32 bits, check here a sample : https://s3-eu-west-1.amazonaws.com/acce ... -47-09.bmp

as you can see , there is no problem to open this bmp is a browser, windows preview or photoshop, so I guess there s no particular problem with the specific file

I try various commands but all with the same result : I get a completly transparent image

convert image.bmp image.png > transparent

convert image.bmp -channel rgba image.png > transparent
convert image.bmp -channel rgb image.png > transparent

identify image.bmp

image.bmp BMP 640x480 640x480+0+0 8-bit sRGB 1.229MB 0.000u 0:
00.005

Any suggestions ?

Re: cant convert bmp to png

Posted: 2012-11-14T08:39:45-07:00
by snibgo
The conversion works fine for me (IM 6.7.9-6, Windows 7).

What version of IM are you running?

Re: cant convert bmp to png

Posted: 2012-11-14T08:42:54-07:00
by ad34
Hi,

ImageMagick-6.8.0-Q16 on windows 7

Re: cant convert bmp to png

Posted: 2012-11-14T11:11:11-07:00
by indiego
@snibgo: better stay with this version. the png is transparent here (IM 6.8.0-4 Q16, Windows 7)

Re: cant convert bmp to png

Posted: 2012-11-14T12:53:54-07:00
by Jason S
The image is valid, and not transparent.

As a workaround, try

Code: Select all

convert image.bmp -alpha off image.png
I think IM just assumes that all 32-bit BMP images use transparency. That's not right -- if anything, it should assume that they don't. Some BMP viewers try to guess, based on the contents of the image.

Re: cant convert bmp to png

Posted: 2012-11-14T13:58:26-07:00
by glennrp
It seems that recent versions of IM have mixed up opacity and transparency in BMP.
Testing with IM-6.8.0-5 from SVN:
"convert rose: -matte rose.bmp" creates a transparent image, when viewed by another app.
Then "convert rose.bmp rose.png" creates the original opaque rose image.

[edit] The current IM-7.0.0 alpha behaves the same way.

Re: cant convert bmp to png

Posted: 2012-11-14T16:16:53-07:00
by Jason S
glennrp wrote:"convert rose: -matte rose.bmp" creates a transparent image, when viewed by another app.
I'm not seeing this problem. With IM 6.8.0-4, I get an image that uses 0xff as the transparency/opacity value. As far as I know, that's correct (opaque).

Re: cant convert bmp to png

Posted: 2012-11-14T16:54:32-07:00
by fmw42
I believe your image is malformed and reports alpha=0 for an opaque image. An opaque image should have alpha=255 (1)

For example:

With PNG, this is correct:

convert rose: -alpha opaque rose_tmp.png
identify -verbose rose_tmp.png

Image: rose_tmp.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 70x46+0+0
Units: Undefined
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 1-bit
...
Alpha:
min: 255 (1)
max: 255 (1)
mean: 255 (1)

standard deviation: 0 (0)
kurtosis: 0
skewness: 0


With BMP, this is correct:

convert rose: -alpha opaque rose_tmp.bmp
identify -verbose rose_tmp.bmp

Image: rose_tmp.bmp
Format: BMP (Microsoft Windows bitmap image)
Class: DirectClass
Geometry: 70x46+0+0
Units: PixelsPerCentimeter
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 1-bit
...
Alpha:
min: 255 (1)
max: 255 (1)
mean: 255 (1)

standard deviation: 0 (0)
kurtosis: 0
skewness: 0


But with your opaque bmp, I get:

identify -verbose KinectSnapshot-04-47-09.bmp
Image: KinectSnapshot-04-47-09.bmp
Format: BMP (Microsoft Windows bitmap image)
Class: DirectClass
Geometry: 640x480+0+0
Units: PixelsPerCentimeter
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 1-bit
...
Alpha:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0

All zeros for alpha normally means perfectly and fully transparent.

Re: cant convert bmp to png

Posted: 2012-11-14T17:13:07-07:00
by Jason S
KinectSnapshot-04-47-09.bmp technically does not have an alpha channel. Its Type is identified incorrectly.

http://msdn.microsoft.com/en-us/library ... 85%29.aspx says
"The value for blue is in the least significant 8 bits, followed by 8 bits each for green and red. The high byte in each DWORD is not used."

Re: cant convert bmp to png

Posted: 2012-11-14T17:18:41-07:00
by fmw42
I am no expert, but there are several versions of bmp. See http://www.imagemagick.org/Usage/formats/#bmp

If you do not know which version you are using, then try

convert BMP2:image.bmp image.png

or

convert BMP3:image.bmp image.png

If that fails, then report this issue on the Bugs forum and reference back to this topic. Be sure to identify your version of IM and platform.

P.S. In the mean time, you can use

convert KinectSnapshot-04-47-09.bmp -alpha off KinectSnapshot-04-47-09.png

to get a non-transparent resulting png.

Re: cant convert bmp to png

Posted: 2012-11-14T20:56:10-07:00
by glennrp
fmw42 wrote:I believe your image is malformed and reports alpha=0 for an opaque image. An opaque image should have alpha=255 (1)

With BMP, this is correct:

convert rose: -alpha opaque rose_tmp.bmp
identify -verbose rose_tmp.bmp
You are using the same buggy codec when you use "identify". Naturally it's self-consistent, Use some other application to find out what's really in the image.

This situation has existed for a while.
[edit]So far I've tested back to 6.4.8-10 which is correct.
[edit]I misread my diagnostics about 6.6.0; it's OK.
6.7.9-9 is OK and 6.8.0-1 is incorrect.