cant convert bmp to png

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ad34
Posts: 2
Joined: 2012-11-14T03:36:39-07:00
Authentication code: 6789

cant convert bmp to png

Post 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 ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: cant convert bmp to png

Post by snibgo »

The conversion works fine for me (IM 6.7.9-6, Windows 7).

What version of IM are you running?
snibgo's IM pages: im.snibgo.com
ad34
Posts: 2
Joined: 2012-11-14T03:36:39-07:00
Authentication code: 6789

Re: cant convert bmp to png

Post by ad34 »

Hi,

ImageMagick-6.8.0-Q16 on windows 7
indiego
Posts: 75
Joined: 2010-10-16T06:35:10-07:00
Authentication code: 8675308

Re: cant convert bmp to png

Post by indiego »

@snibgo: better stay with this version. the png is transparent here (IM 6.8.0-4 Q16, Windows 7)
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Re: cant convert bmp to png

Post 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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: cant convert bmp to png

Post 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.
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Re: cant convert bmp to png

Post 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).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: cant convert bmp to png

Post 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.
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Re: cant convert bmp to png

Post 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."
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: cant convert bmp to png

Post 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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: cant convert bmp to png

Post 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.
Post Reply