CreatePatternBrush 和屏幕颜色深度
我正在使用 CreatePatternBrush 创建画笔,并使用 CreateBitmap 创建位图。
位图的宽度为 1 像素,高度为 24 像素,我有每个像素的 RGB 值,因此我创建了一个 rgbquad 数组并将其传递给 CreateBitmap。
当屏幕颜色深度为 32bpp 时,此方法效果很好,因为我创建的位图也是 32bpp。
当屏幕颜色深度不是 32bpp 时,此操作会失败,我明白为什么会这样,因为我应该创建一个兼容的位图。
看来我应该使用 CreateCompatibleBitmap 来代替,但是如何将我拥有的像素数据放入该位图中?
我还阅读了有关 CreateDIBPatternBrushPt、CreateDIBitmap、CreateDIBSection 等的内容。
我不明白什么是 DIBSection,并且发现该主题通常令人困惑。
我确实知道我需要一个与屏幕颜色深度相同的位图,但是如何创建只有 32bpp 像素数据的位图?
I am creating a brush using CreatePatternBrush with a bitmap created with CreateBitmap.
The bitmap is 1 pixel wide and 24 pixels tall, I have the RGB value for each pixel, so I create an array of rgbquads and pass that to CreateBitmap.
This works fine when the screen color depth is 32bpp, since the bitmap I create is also 32bpp.
When the screen color depth is not 32bpp, this fails, and I understand why it does, since I should be creating a compatible bitmap instead.
It seems I should use CreateCompatibleBitmap instead, but how do I put the pixel data I have into that bitmap?
I have also read about CreateDIBPatternBrushPt, CreateDIBitmap, CreateDIBSection, etc.
I don´t understand what is a DIBSection, and find the subject generally confusing.
I do understand that I need a bitmap with the same color depth as the screen, but how do I create it having only the 32bpp pixel data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建 DIB,因为您可以使用独立于屏幕颜色深度的设备独立位图。请参阅 CreateDIBSection()。
如何创建只有 32bpp 像素数据的它?可以使用 32bpp 数据创建 DIB。正如您在文档中所读到的:
尝试这样的操作:
在我们的例子中,*ppvBits 指向 1 * 24 * (32 / 8) 分配的字节。
重要的是要知道,如果 biHeight 为正,则位图是自下而上的 DIB,其原点是左下角。有关详细信息,请参阅BITMAPINFOHEADER 结构 。
You could create a DIB because you can use a Device Independent Bitmap independently of the screen color depth. See CreateDIBSection().
How can you create it having only the 32bpp pixel data? A DIB can be created with 32bpp data. As you can read in the documentation:
Try something like this:
In our case *ppvBits points to 1 * 24 * (32 / 8) allocated bytes.
It is important to know that if biHeight is positive, the bitmap is a bottom-up DIB and its origin is the lower-left corner. See BITMAPINFOHEADER Structure for more info.
我通过使用 CreateCompatibleBitmap 和 SetPixel 解决了这个问题。我认为这不是最好的选择,但它确实有效。
I solved it by using CreateCompatibleBitmap and SetPixel. Not the best option I guess, but it works.