如何为 WORD 分配 RGB 颜色代码?
我将颜色值分配给显示帧缓冲区,并且该缓冲区指针返回类型是 BYTE。但我无法将 RGB 颜色值分配给它。我这样做是为了在 WINCE 平台上使用 directdraw 设置像素位置。这是快照代码。
BYTE* pDisplayMemOffset = (BYTE*) ddsd.lpSurface;
int x = 100;
int y = 100;
pDisplayMemOffset += x*ddds.lXPitch + y*ddds.lPitch ;
***(WORD*)pDisplayMemOffset = 0x0f00;
但是我如何在其中分配 RGB(100,150,100) 组合,我尝试在分配时使用 DWORD 而不是 WORD,但它不起作用。我知道我需要 0x000000 格式(RGB)颜色的十六进制值,但我认为 BYTE cnt 将如此大的值存储到其中。
谁能告诉我该怎么做?
I am assigning the color values to the display frame buffer, and that buffer pointer return type is BYTE. But i am not able to assign the RGB color value into it. This i am doing to set the pixel location using directdraw on WINCE platform .Here is the snapshot code.
BYTE* pDisplayMemOffset = (BYTE*) ddsd.lpSurface;
int x = 100;
int y = 100;
pDisplayMemOffset += x*ddds.lXPitch + y*ddds.lPitch ;
***(WORD*)pDisplayMemOffset = 0x0f00;
But how i can assign RGB(100,150,100) combination in this, i have tried to put DWORD instead of WORD while assigment but it desnt work. i knw i required hex value for color in 0x000000 format(RGB), but i think BYTE cnt store such large value into it.
Can anyone tell me how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何完成此分配很大程度上取决于您在获取 ddsd 时指定的像素格式。请参阅
ddpfPixelFormat
字段以及其中的具体内容:dwRGBBitCount
。也许您可以提供此像素格式信息,以便我可以改进我的答案。但是,我可以轻松地为您提供一个示例,说明如何执行此像素颜色分配,例如像素格式是:
这是示例:
如果必须从整数中提取颜色值,则很大程度上取决于字节顺序和对给出的整数进行颜色排序,但您可以轻松尝试。
首先我会尝试这个:
如果这有效,那么像素格式要么有一个未使用的第四个字节(如上面的示例),要么有一个现在设置为其中一个值的 alpha 值。再次强调:除了像素格式之外,整数中的字节顺序也决定了这是否直接起作用或者是否必须进行一些字节交换。
How this assignment can be done is very dependent on the pixel-format you specified when acquiring
ddsd
. See the fieldddpfPixelFormat
and also specifically in there:dwRGBBitCount
.Maybe you can provide this pixel format information so that i can improve my answer. However, i can easily give you an example of how you do this pixel-color assignment if e.g. the pixel-format is:
Here's the example:
If you have to extract the color values from an integer it largely depends on which byte-ordering and color-ordering that integer was given in, but you can try it out easily.
First i would try this:
If this works, then the pixel-format had either an unused 4th byte (like my example above) or an alpha-value that is now set to one of the values. Again: aside from the pixel-format also the ordering of the bytes in your integer decides whether this directly works or whether you have to do some byte-swapping.