Save the bitmap image after convert to 1 bit monochrome

  • Thread starter Thread starter KQWong
  • Start date Start date
K

KQWong

Guest
Hi, Im using GDI+ to convert the bitmap pixel format from 24bit to 1 bit by using below code:

GdiplusStartupInput sti; // Initialize Gdiplus
ULONG_PTR gpToken;
int n = sizeof sti;
GdiplusStartup(&gpToken, &sti, NULL);
Bitmap* myBitmap = new Bitmap(Bitmap Path Name); // Load the bitmap from the path name
PixelFormat pxf = myBitmap->GetPixelFormat();
Gdiplus::ColorPalette* pal = (Gdiplus::ColorPalette*)malloc(sizeof(Gdiplus::ColorPalette) + 2 * sizeof(Gdiplus::ARGB));
pal->Count = 2;
pal->Flags = 0;
Gdiplus::Bitmap::InitializePalette(pal, Gdiplus::PaletteTypeFixedBW, 2, FALSE, NULL);
// Convert the bitmap pixel format to 1 bit monochrome (PixelFormat1bppIndexed)
myBitmap->ConvertFormat(PixelFormat1bppIndexed, Gdiplus::DitherTypeErrorDiffusion, Gdiplus::PaletteTypeFixedBW, pal, 0);
pxf = myBitmap->GetPixelFormat();

After convert the pixel format successfully, I'm facing the problem to save this altered bitmap image, can anyone please help me on this problem T.T

Thanks!

Continue reading...
 
Back
Top