Page 1 of 1

Loading and outputting .BMP images.

Posted: 2013-04-05T22:22:10-07:00
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

Re: Loading and outputting .BMP images.

Posted: 2013-04-06T08:42:25-07:00
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