如何保存1bpp, 4bpp和8BPP图像

How to save 1 BPP, 4 BPP and 8BPP image

本文关键字:4bpp 8BPP 图像 1bpp 何保存 保存      更新时间:2023-10-16

谁能告诉我如何将1BPP, 4BPP和8BPP保存为位图?图像中有位,宽度和高度。

请告诉我如何将其保存为位图

对于Windows和c++,最简单的方法是Gdiplus。下面是一些伪代码。

Gdiplus::Bitmap* pBmp = new Gdiplus::Bitmap(width, height, pixelformat);
pBmp->SetPalette(...); // initialize palette for 8bpp formats and less
pBmp->LockBits(...); // acquire the bitmap buffer
// copy your binary image data into the buffer
pBmp->UnlockBits(...); // return the buffer
pBmp->Save(filename, &clsidBMP, NULL);
delete pBmp;

您可以在这里获得GDI plus定义的像素格式列表。

您需要的大部分内容都是由Bitmap类定义的,它继承自Image类,后者定义了Save方法。

"save"方法所需的编码器分类有点棘手。但是请参阅我在这里发布的关于如何获取此值的帖子。

ATL::CImage* image_ = new CImage();
image_ -> Create( rect.right - rect.left, rect.bottom - rect.top, 32 );
...
image_ -> Save( filename );
delete image_;