gpt4 book ai didi

windows - CreatePatternBrush 和屏幕颜色深度

转载 作者:可可西里 更新时间:2023-11-01 10:29:54 25 4
gpt4 key购买 nike

我正在使用 CreatePatternBrush 和使用 CreateBitmap 创建的位图创建画笔。

位图是 1 像素宽和 24 像素高,我有每个像素的 RGB 值,所以我创建了一个 rgbquads 数组并将其传递给 CreateBitmap。

当屏幕颜色深度为 32bpp 时效果很好,因为我创建的位图也是 32bpp。

当屏幕颜色深度不是 32bpp 时,这会失败,我明白为什么会这样,因为我应该创建一个兼容的位图。

看来我应该改用 CreateCompatibleBitmap,但如何将我拥有的像素数据放入该位图中?

我还阅读了有关 CreateDIBPatternBrushPt、CreateDIBitmap、CreateDIBSection 等的内容。

我不明白什么是 DIBSection,并且发现这个主题通常令人困惑。

我知道我需要一个与屏幕颜色深度相同的位图,但我如何创建它只有 32bpp 像素数据?

最佳答案

您可以创建 DIB,因为您可以使用独立于屏幕颜色深度的设备独立位图。参见 CreateDIBSection() .

如何创建只有 32bpp 像素数据的它?可以使用 32bpp 数据创建 DIB。正如您在文档中看到的那样:

The CreateDIBSection function creates a DIB that applications can write to directly. The function gives you a pointer to the location of the bitmap bit values. If hSection is NULL, the system allocates memory for the DIB. If the function succeeds, the return value is a handle to the newly created DIB, and *ppvBits points to the bitmap bit values.

尝试这样的事情:

VOID *ppvBits = NULL;
BITMAPINFO BitmapInfo;
memset(&BitmapInfo, 0, sizeof(BITMAPINFOHEADER));
BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfo.bmiHeader.biWidth = 1;
BitmapInfo.bmiHeader.biHeight = 24;
BitmapInfo.bmiHeader.biPlanes = 1;
BitmapInfo.bmiHeader.biBitCount = 32;
BitmapInfo.bmiHeader.biCompression = BI_RGB;
HBITMAP hBitmap = CreateDIBSection(hDC, &BitmapInfo, DIB_RGB_COLORS, &ppvBits, NULL, 0);

在我们的例子中,*ppvBits 指向 1 * 24 * (32/8) 个分配的字节。

重要的是要知道,如果 biHeight 为正,则位图为自下而上的 DIB,其原点为左下角。参见 BITMAPINFOHEADER Structure了解更多信息。

关于windows - CreatePatternBrush 和屏幕颜色深度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2975757/

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