Search code examples
c++bitmaploadimage

LoadImage Function isn't Working With ImageMagick Created Bitmap Images


I am trying to load some bitmap images with my application to do some comparisons whose created using ImageMagick using following command:

C:\Program Files\ImageMagick-7.0.6-Q16>Convert << SOURCE BMP >> -crop -650 << DEST BMP >>

Above source bitmap image loads fine with LoadImage API Function, but the image created by ImageMagick (destination bitmap) fails to load.

How I am using LoadImage Function:

HBitmapRight = (HBITMAP)LoadImage(nullptr, L"C:\\DEST.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE);
HBitmapRight = (HBITMAP)LoadImage(nullptr, L"C:\\SOURCE.bmp", IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE);

I used GetLastError, but it returned ERROR_SUCCESS.

Upon my research, I found this answer and so, this maybe a encoding issue or something similar.

Unfortunately I cannot use any tools like MS Paint or Photoshop, but I only can use ImageMagick because this comparison is done using command line without user interaction.

Is it possible to set any special encoding flags to be used with ImageMagick, so bitmap images creating by it can be compatible with LoadImage?

I am running this application in my Windows 7 64-bit machine and installed ImageMagick is also the latest 64-bit version of it. Compiler is MS Visual C++ 2017.

Those are the lines that causes the issue:

<Mask>
<Red/>
<Green/>
<Blue/>
<Alpha/>
</Mask>
<ColorSpaceType/>
<CIEXYZEndPoints>
<Red>
<X/>
<Y/>
<Z/>
</Red>
<Green>
<X/>
<Y/>
<Z/>
</Green>
<Blue>
<X/>
<Y/>
<Z/>
</Blue>
</CIEXYZEndPoints>
<Intent/>

These lines are in XML metadata of ImageMagick created image. I checked with source image, it doesn't have those lines.

Please help me to resolve this issue without user interaction.


Solution

  • I fixed the problem by changing my ImageMagick command to use specific version of Bitmap format like this:

    C:\Program Files\ImageMagick-7.0.6-Q16>Convert << SOURCE BMP >> -define bmp:format=bmp3 -crop -650 << DEST BMP >>
    

    Now LoadImage API function works fine with ImageMagick created bitmap images.