Given an HDC, I would like to figure out not only how many bits of Red, Green, Blue and Alpha there are (using DescribePixelFormat), but even their layout (BGR(A) or RGB(A)) so that I can perform pixel and color component level manipulation.

Should I always assume they're in BGR(A) order? Is that a reasonable assumption?

有帮助吗?

解决方案

http://msdn.microsoft.com/en-us/library/dd183449(VS.85).aspx

That's the docs for COLORREF which is stored as 0x00BBGGRR.

According to that which is used by most of WINAPI, I'd have to assume that everything on Windows is actually stored in BGRA format.. AFAIK, DIBs are in BGRA format.

You can try painting a window red. Create a DIB section and copy the pixels into a buffer. If the first byte is 0xFF, it is RGBA otherwise it is BGRA.

GDI32 images always stores as BGRA on my machine. GDI24 images are always BGR. I have released an Image handling API and of all the users, I haven't met a single one that has not had the same format. I have yet to see a DC or default backbuffer format in RGBA instead of BGRA.

What is the reason you really need to know the format of a DC? I never found myself wanting to know.

When reading an image, you figure out the bit count from the BitmapInfoHeader.biBitCount field.

其他提示

According to the docs for the PIXELFORMATDESCRIPTOR:

iPixelType Specifies the type of pixel data. The following types are defined: PFD_TYPE_RGBA RGBA pixels. Each pixel has four components in this order: red, green, blue, and alpha. PFD_TYPE_COLORINDEX Color-index pixels. Each pixel uses a color-index value.

So it seems like they're either RGBA or indexed.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top