Convert PNG to 8-Bit Palette BMP

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
nm-osm
Posts: 6
Joined: 2015-04-21T03:11:23-07:00
Authentication code: 6789

Convert PNG to 8-Bit Palette BMP

Post by nm-osm »

The PNG has 31 colors as reported from totalColors(). My code is:

Code: Select all

// img has a type with const char *data() and size_t length()
Magick::Blob inblob( img.data(), img.length() );
Magick::Image image;
image.read( inblob );
image.compressType( MagickCore::NoCompression );
image.type( MagickCore::PaletteType );
image.colorMapSize( 256 );
Magick::Blob outblob;
image.write( &outblob, "bmp3" );
The resulting image is barely visible, the colors are reduced to a dark grey. The CLI-tool convert works OK.
  • $ convert x.png -type Palette -depth 8 -compress none bmp3:x.bmp
I have tried with various combinations of
  • image.quantizeColors( 256 )
    image.depth( 8 )
    image.depth( 24 )
    image.classType( MagickCore::DirectClass )
    image.classType( MagickCore::PseudoClass )
    image.colorSpace( MagickCore::sRGBColorspace )
    image.colorspaceType( MagickCore::sRGBColorspace )
    image.quantize()
Has anyone an idea how to transfer the 31 colors from the PNR into the colormap with fidelity?

TIA
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert PNG to 8-Bit Palette BMP

Post by fmw42 »

I would suggest you provide your version of IM and platform and also post your PNG image so others can test using the command line.
nm-osm
Posts: 6
Joined: 2015-04-21T03:11:23-07:00
Authentication code: 6789

Re: Convert PNG to 8-Bit Palette BMP

Post by nm-osm »

The version is ImageMagick-6.9.1-1, platform is SUSE Linux Enterprise Server 11.

How do I post an image? I have seen images posted by others but not found a way to do it myself :-(. There is no button to add an attachment.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert PNG to 8-Bit Palette BMP

Post by fmw42 »

You must post to some free service such as dropbox.com and then put the URL here.
nm-osm
Posts: 6
Joined: 2015-04-21T03:11:23-07:00
Authentication code: 6789

Re: Convert PNG to 8-Bit Palette BMP

Post by nm-osm »

I have put the pictures on flickr:

imagemagick-input.png = https://www.flickr.com/photos/132066708 ... 310395011/
imagemagick-output.bmp = https://www.flickr.com/photos/132066708 ... 103444757/

Sorry about the delay but I was on vacation the last days.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert PNG to 8-Bit Palette BMP

Post by fmw42 »

This seems to work for me on IM 6.9.1.3 Q16 Mac OSX in the command line.

Note your png file has a totally opaque alpha channel which I removed.

Code: Select all

convert 17310395011_f1a497f25f_o.png -alpha off -type palette BMP3:17310395011_f1a497f25f_o.bmp
Sorry, I do not know the Magick++ API equivalent.
nm-osm
Posts: 6
Joined: 2015-04-21T03:11:23-07:00
Authentication code: 6789

Re: Convert PNG to 8-Bit Palette BMP

Post by nm-osm »

As I wrote it's works for me on the command-line too. The problem is with the C++-API.
nm-osm
Posts: 6
Joined: 2015-04-21T03:11:23-07:00
Authentication code: 6789

Re: Convert PNG to 8-Bit Palette BMP

Post by nm-osm »

We have ceased to use IM for this -> problem solved.
cuongvn08
Posts: 6
Joined: 2017-01-09T23:50:54-07:00
Authentication code: 1151

Re: Convert PNG to 8-Bit Palette BMP

Post by cuongvn08 »

nm-osm wrote: 2015-05-12T03:35:43-07:00 We have ceased to use IM for this -> problem solved.
I also have same problem as your issue. I would like to convert the original image to 8-bit palette bmp.
I am thinking to stop using IM and change to another library. My programming platform is Ubuntu, php.
So what is the library you are using now?
And how can you fix this issue.
Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert PNG to 8-Bit Palette BMP

Post by fmw42 »

If it works from the command line, then there should be an equivalent for Magick++. Did you try prefacing your output image with BMP3:output.bmp? Sorry, I do not know Magick++, but someone should be able to help.
nm-osm
Posts: 6
Joined: 2015-04-21T03:11:23-07:00
Authentication code: 6789

Re: Convert PNG to 8-Bit Palette BMP

Post by nm-osm »

cuongvn08 wrote: 2017-01-10T19:38:53-07:00 So what is the library you are using now?
Sorry, no library. We convert the pictures with an external script before the c++ program has to handle them.
Post Reply