Using C API I want to convert a .bmp file to a .bmp with the following properties:
color depth 8bits
colorspace grayScale
resolution 500x500 ppi
size 344x360
NoCompression
According to bitmap file format referenced in https://en.wikipedia.org/wiki/BMP_file_format:
The C API converted image shows at offset:
0x1C (biBitCount) = 8
0x1E (biCompression) = 1 (should be 0)
The following command line converts the image correctly.
magick convert tmp.bmp -resample 196x196 -resize 344x360 -grayscale Rec601Luma -depth 8 -alpha off -compress NONE -colors 256 tmp8_cmd.bmp
Our machine can read the image converted by command line and can not read the one converted by C API.
We have to convert using C API.
So the question is:
How to get the BiCompression to be 0? Or
How to convert the image using C API to get the same image as it was converted using above mentioned command line?
Following is the not working C API:
Code: Select all
#include <stdio.h>
#include <iostream>
#include <tchar.h>
#include <windows.h>
#include <wand\magick_wand.h>
int _tmain(int argc, _TCHAR* argv[])
{
MagickWand *l_wand = NULL;
MagickWandGenesis();
l_wand = NewMagickWand();
MagickReadImage( l_wand, "D:\\JPG\\tmp.bmp");
MagickResizeImage( l_wand, 344, 360, CatromFilter, 1.0);
MagickSetImageUnits( l_wand, PixelsPerInchResolution);
MagickSetImageResolution( l_wand, 400, 400);
MagickSetImageDepth( l_wand, 8);
MagickSetImageAlphaChannel( l_wand, DeactivateAlphaChannel);
MagickSetImageCompression( l_wand, NoCompression);
MagickSetImageType( l_wand, GrayscaleType);
MagickQuantizeImage( l_wand, 256, Rec601LumaColorspace, 0, 0, 0);
MagickWriteImage( l_wand, "D:\\JPG\\tmp8.bmp");
if(l_wand) l_wand = DestroyMagickWand(l_wand);
MagickWandTerminus();
return 0;
}
Version: ImageMagick 7.0.2-7 Q8 x64 2016-08-06 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib
Thanks
Grant