gpt4 book ai didi

c++ - 如何保存 1 BPP、4 BPP 和 8BPP 图像

转载 作者:行者123 更新时间:2023-11-28 08:16:43 24 4
gpt4 key购买 nike

谁能告诉我如何将 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定义的像素格式列表加上here .

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

“保存”方法所需的编码器 clsid 获取起来有点棘手。但是看我的贴here关于如何获取这个值。

关于c++ - 如何保存 1 BPP、4 BPP 和 8BPP 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7482811/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com