Created
June 9, 2011 17:22
-
-
Save kimoto/1017220 to your computer and use it in GitHub Desktop.
メモリ中のHBITMAPのデータにImageMagickで処理
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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