0
我閱讀了關於位圖的本教程http://tipsandtricks.runicsoft.com/Cpp/BitmapTutorial.html,它確實有助於......我需要從像素數組的元素中讀取顏色整數值。怎麼做? 確定繼承人用於將數據放入數組RGB代碼從像素數組中加載顏色值
BYTE* ConvertBMPToRGBBuffer (BYTE* Buffer, int width, int height)
{
if ((NULL == Buffer) || (width == 0) || (height == 0))
return NULL;
// find the number of padding bytes
int padding = 0;
int scanlinebytes = width * 3;
while ((scanlinebytes + padding) % 4 != 0) // DWORD = 4 bytes
padding++;
// get the padded scanline width
int psw = scanlinebytes + padding;
// create new buffer
BYTE* newbuf = new BYTE[width*height*3];
// now we loop trough all bytes of the original buffer,
// swap the R and B bytes and the scanlines
long bufpos = 0;
long newpos = 0;
for (int y = 0; y < height; y++)
for (int x = 0; x < 3 * width; x+=3)
{
newpos = y * 3 * width + x;
bufpos = (height - y - 1) * psw + x;
newbuf[newpos] = Buffer[bufpos + 2];
newbuf[newpos + 1] = Buffer[bufpos+1];
newbuf[newpos + 2] = Buffer[bufpos];
}
return newbuf;
}
哥們,如果你希望人們在這裏幫助你,你應該提供你迄今爲止的代碼,而不是期望人們爲你做所有的工作。 – guitarflow 2012-02-20 23:21:54
難道你不想添加標籤'gdi'?也許提供一些代碼,展示你的一些努力,你嘗試了什麼...也許你想問的問題不會比*「如何做到這一點?」* ... – LihO 2012-02-20 23:23:40
現在你的問題是什麼?如何獲得紅色,綠色和藍色的一個值? – guitarflow 2012-02-20 23:53:01