Loading and outputting .BMP images.

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
martinsk
Posts: 1
Joined: 2013-04-05T22:15:24-07:00
Authentication code: 6789

Loading and outputting .BMP images.

Post by martinsk »

I recently got hold of a lot of binary images. The images are stored 128x128 bmp's and I would like to load them and save them as binary png's.

To start of I've taken the tutorial code :

Code: Select all

using namespace std; 

int main(int argc,char **argv)
{ 
  Magick::InitializeMagick(*argv);
  

  try { 
    Magick::Image image;
    
    // read the image from a file 
    image.read(argv[1]);
        
    cout << "image: " << argv[1] << endl; 
    cout << image.columns() << endl;
    cout << image.rows() << endl;
    
    image.crop( Magick::Geometry(127, 127, 0, 0) );
 
    // Write the image to a file 
    image.write( argv[2] ); 

  } 
  catch( Magick::Exception &error_ ) { 
    cout << "Caught exception: " << error_.what() << endl; 
      return 1; 
  }
  
  return 0; 
}
The code compiles and runs but the outputtet bmp -> bmp, but the outputtet bmp claims to be have size 0x0, which does not seam right, since it has the same size(byte vise) as the original.

The code is run:

Code: Select all

> convertbmp2bmp inputfile.bmp outputfile.bmp
on this bmp image http://ge.tt/3SiPaDd/v/0?c

can someone please tell me what happens to the bmp when I load it and save it again -- it would aprear to me that some information goes missing
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Loading and outputting .BMP images.

Post by el_supremo »

That code works for me with your input file and converting to a BMP. But to output a PNG you need to add a page statement after the crop:

Code: Select all

	image.page( Magick::Geometry(127, 127, 0, 0) );
Otherwise you will have a 127x127 image on a 128x128 canvas.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
Post Reply