Skip to content

Instantly share code, notes, and snippets.

@kimoto
Created June 9, 2011 17:22
Show Gist options
  • Select an option

  • Save kimoto/1017220 to your computer and use it in GitHub Desktop.

Select an option

Save kimoto/1017220 to your computer and use it in GitHub Desktop.
メモリ中のHBITMAPのデータにImageMagickで処理
// HBITMAPからデータを取得
BITMAP bmp;
::GetObject(hBitmap, sizeof(BITMAP), &bmp);
int len = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
BYTE *p = (BYTE *)malloc(len * sizeof(BYTE));
::GetBitmapBits(hBitmap, len, p);
int width = bmp.bmWidth;
int height = bmp.bmHeight;
int depth = 8;
// ImageMagickに渡す
::Magick::Image image;
image.read(width, height, "BGRA", Magick::CharPixel, p);
// ImageMagickで処理
image.quantizeDither(true);
image.quantizeColors(256); // 256に減色処理
image.quantize();
// HBITMAPに戻す
image.write(0, 0, width, height, "BGRA", Magick::CharPixel, p);
::SetBitmapBits(hBitmap, len, p);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment