0
我需要在位圖像素中交換RGBA通道。例如,.net圖形在BGRA中將通道寫入位圖,我需要RGBA。我認爲這個順序由PIXELFORMATDESCRIPTOR確定,但我不知道如何。我做如下更改像素格式以繪製位圖
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_BITMAP | // support window
PFD_SUPPORT_OPENGL |
PFD_NEED_PALETTE,
PFD_TYPE_COLORINDEX, // RGBA type
32, // 24-bit color depth
8, 8, 8, 0, 0, 0, // color bits ignored
8, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
int iPixelFormat;
::SelectObject ((HDC)_hdc.ToPointer(), (HBITMAP)_hBitmap.ToPointer());
iPixelFormat = ChoosePixelFormat((HDC)_hdc.ToPointer(), &pfd);
bool result = ::SetPixelFormat((HDC)_hdc.ToPointer(), iPixelFormat, &pfd);
我試圖改變頻道的轉移,但它什麼都不做。
感謝您的回答。它可以幫助,如果我只繪製圖像轉換成位圖我的,但我畫直線,矩形等。根據它我可以重繪我的顏色表位,但它是繪製圖像兩次,這是沒有必要的,因爲我可以換我的頻道直接在內存中。我在抽獎時間考慮顏色地圖。 –
爲什麼每次繪製東西時都需要轉置位?它是不夠的,做一次 - 無論是在開始或結束了嗎?你究竟想要做什麼? – Ani
我使用vtk庫來可視化這個位圖,而vtk使用位圖的RGBA配色方案,而不是BGRA,它在繪畫之後爲我提供了圖形。現在是直接可視化之前交換B和R。 –