線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1521
推到 Plurk!
推到 Facebook!

影像指標

答題得分者是:senso
encoref70036
一般會員


發表:29
回覆:47
積分:15
註冊:2011-05-18

發送簡訊給我
#1 引用回覆 回覆 發表時間:2011-08-03 23:41:28 IP:111.253.xxx.xxx 訂閱
你好
請問這段程式碼中
Byte *ptr1,*aptr1;
for (int y = 0;y < nBitmap->Height;y )
{
ptr1 = (Byte*)nBitmap->ScanLine[y];
aptr1 = (Byte*)pBitmap->ScanLine[y];
for (int x = 0;x < nBitmap->Width;x )
{
aptr1[4*x] = ptr1[3*x];
aptr1[4*x 1] = ptr1[3*x 1];
aptr1[4*x 2] = ptr1[3*x 2];
}
}
為什麼 aptr1[4*x]就是32位元的B、aptr1[4*x 1]32位元的G、aptr1[4*x 2]32位元的R?
是怎麼算的呢?

senso
高階會員


發表:5
回覆:126
積分:226
註冊:2003-11-27

發送簡訊給我
#2 引用回覆 回覆 發表時間:2011-08-05 10:30:32 IP:61.219.xxx.xxx 訂閱
pf32bit是每Pixel以4byte儲存,所以讀取自然就是[4*x]、[4*x+1]、[4*x+2]
至順序是BGR是因為Little Endian的關係
值0x00RRGGBB以Little Endian存到記憶體後順序就變成BB、GG、RR、00

參考
http://zh.wikipedia.org/wiki/BMP
http://crazycat1130.pixnet.net/blog/post/1345538
http://www.google.com.tw/search?q=Big Endian Little Endian&oq=Big Endian Little Endian
http://www.cs.umass.edu/~verts/cs32/endian.html
encoref70036
一般會員


發表:29
回覆:47
積分:15
註冊:2011-05-18

發送簡訊給我
#3 引用回覆 回覆 發表時間:2011-08-05 21:40:05 IP:111.253.xxx.xxx 訂閱
那8位元調色盤上的顏色是這樣寫嗎?
ptr1[x];//B
ptr1[x 1];//G
ptr[x 2];//R
因為我想把8位元調色盤上面的顏色 給32位元的R、G、B
但是8位元上面的顏色好像是這樣
Graphics::TBitmap *tmpBmp = new Graphics::TBitmap();
tmpBmp->Assign(Image1->Picture->Bitmap);
PALETTEENTRY greyPal[256];
HPALETTE hPal = tmpBmp->ReleasePalette();
GetPaletteEntries(hPal, 0, 256, greyPal);
for (int index = 0; index < 256; index )
{
greyPal[index].peBlue
greyPal[index].peGreen
greyPal[index].peRed
}
我不知道要怎麼把顏色丟給32位元上的R、G、B
因為index是0~255
但是32位元是這樣
for (int x = 0;x < nBitmap->Width;x )
{
aptr1[4*x]
aptr1[4*x 1]
aptr1[4*x 2]
}
他的x是0~圖片的寬度
編輯記錄
encoref70036 重新編輯於 2011-08-05 08:18:51, 註解 無‧
encoref70036 重新編輯於 2011-08-06 05:17:23, 註解 無‧
encoref70036 重新編輯於 2011-08-06 05:23:12, 註解 無‧
senso
高階會員


發表:5
回覆:126
積分:226
註冊:2003-11-27

發送簡訊給我
#4 引用回覆 回覆 發表時間:2011-08-06 22:00:17 IP:114.42.xxx.xxx 訂閱
把pf8的值當調色盤的索引,取RGB值
還是丟code好了...

[code cpp]
Graphics::TBitmap *bmp1 = new Graphics::TBitmap();
Graphics::TBitmap *bmp2 = new Graphics::TBitmap();
bmp1->LoadFromFile("D:\\senso\\temp\\640x480x8b.bmp");
bmp2->PixelFormat=pf32bit;
bmp2->Width=bmp1->Width;
bmp2->Height=bmp1->Height;
PALETTEENTRY greyPal[256];
HPALETTE hPal = bmp1->Palette; //沒要改調色盤就不用release了
GetPaletteEntries(hPal, 0, 256, greyPal);
for (int i=0;iHeight;i )
{
Byte *ptr1 = (Byte*)bmp1->ScanLine[i];
Byte *ptr2 = (Byte*)bmp2->ScanLine[i];
for (int j=0;jWidth;j )
{ //把pf8的值當調色盤的索引,取RGB值
ptr2[4*j] = greyPal[ptr1[j]].peBlue;
ptr2[4*j 1] = greyPal[ptr1[j]].peGreen;
ptr2[4*j 2] = greyPal[ptr1[j]].peRed;
ptr2[4*j 3] = 0;
}
}
Form1->Canvas->Draw(0,0,bmp2);
delete bmp1,bmp2;
[/code]

編輯記錄
senso 重新編輯於 2011-08-06 08:02:01, 註解 無‧
encoref70036
一般會員


發表:29
回覆:47
積分:15
註冊:2011-05-18

發送簡訊給我
#5 引用回覆 回覆 發表時間:2011-08-06 23:29:51 IP:111.253.xxx.xxx 訂閱
大俠 你好神!! 這個問題我想了好久ˊˋ 呵呵 真的很感謝您
系統時間:2024-03-29 3:49:28
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!