如何为 WORD 分配 RGB 颜色代码?

发布于 2024-10-21 13:48:31 字数 452 浏览 3 评论 0原文

我将颜色值分配给显示帧缓冲区,并且该缓冲区指针返回类型是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等数载,海棠开 2024-10-28 13:48:31

如何完成此分配很大程度上取决于您在获取 ddsd 时指定的像素格式。请参阅ddpfPixelFormat字段以及其中的具体内容:dwRGBBitCount

也许您可以提供此像素格式信息,以便我可以改进我的答案。但是,我可以轻松地为您提供一个示例,说明如何执行此像素颜色分配,例如像素格式是:

[1 byte red] [1 byte green] [1 byte blue] [1 byte unused]

这是示例:

*(pDisplayMemOffset+0) = 0x10;// asigning 0x10 to the red-value of first pixel
*(pDisplayMemOffset+1) = 123; // asigning 123 to green-value of first pixel 
                              // (no need for hex)
*(pDisplayMemOffset+4) = 200; // asigning 200 to red-value of second pixel
                              // (BYTE is unsigned)

如果必须从整数中提取颜色值,则很大程度上取决于字节顺序和对给出的整数进行颜色排序,但您可以轻松尝试。

首先我会尝试这个:

*(((unsigned int*)pDisplayMemOffset)+0) = 0x1A2A3A4A
*(((unsigned int*)pDisplayMemOffset)+1) = 0x1B2B3B4B

如果这有效,那么像素格式要么有一个未使用的第四个字节(如上面的示例),要么有一个现在设置为其中一个值的 alpha 值。再次强调:除了像素格式之外,整数中的字节顺序也决定了这是否直接起作用或者是否必须进行一些字节交换。

How this assignment can be done is very dependent on the pixel-format you specified when acquiring ddsd. See the field ddpfPixelFormat 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:

[1 byte red] [1 byte green] [1 byte blue] [1 byte unused]

Here's the example:

*(pDisplayMemOffset+0) = 0x10;// asigning 0x10 to the red-value of first pixel
*(pDisplayMemOffset+1) = 123; // asigning 123 to green-value of first pixel 
                              // (no need for hex)
*(pDisplayMemOffset+4) = 200; // asigning 200 to red-value of second pixel
                              // (BYTE is unsigned)

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:

*(((unsigned int*)pDisplayMemOffset)+0) = 0x1A2A3A4A
*(((unsigned int*)pDisplayMemOffset)+1) = 0x1B2B3B4B

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文