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

RGB 24bit 轉 RGB565 16bit

缺席
ychong
一般會員


發表:1
回覆:1
積分:0
註冊:2005-03-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-03-14 13:39:44 IP:59.120.xxx.xxx 訂閱
各位好:
想請問一下RGB 24bit 轉 RGB 16bit 後,顯示出來的顏色不正常
不確定是哪個環節出問題了,請各位幫我解惑,謝謝

RGB565圖例:


下列是我的程式碼與原始檔:

[code cpp]
//---------------------------------------------------------------------------
void __fastcall TMain_Form::Open1Click(TObject *Sender)
{
pBitmap = new Graphics::TBitmap();
TRGBTriple *ptr;
int x,y;
if (OpenPictureDialog1->Execute())
{
try
{
pBitmap->LoadFromFile(OpenPictureDialog1->FileName);
nWe = pBitmap->Width;
nHi = pBitmap->Height;
pBitmap->PixelFormat = pf24bit;
RGB_888Ary = new TRGBTriple[nHi*nWe];
RGB_565Ary = new TRGBTriple[nHi*nWe];
for (y = 0; y < nHi; y )
{
ptr = (TRGBTriple *)pBitmap->ScanLine[y];
for (x = 0; x < nWe; x )
{
RGB_888Ary[y*nWe x] = ptr[x];
RGB_565Ary[y*nWe x].rgbtRed = (Byte)ptr[x].rgbtRed >> 3; // 5-bit red
RGB_565Ary[y*nWe x].rgbtGreen = (Byte)ptr[x].rgbtGreen >> 2; // 6-bit green
RGB_565Ary[y*nWe x].rgbtBlue = (Byte)ptr[x].rgbtBlue >> 3; // 5-bit blue
}
}
Image1->Picture->Bitmap->Assign(pBitmap);
}
catch (...)
{
ShowMessage("Could not load or alter bitmap");
}
delete pBitmap;
}
}
//---------------------------------------------------------------------------

void __fastcall TMain_Form::BitBtn1Click(TObject *Sender)
{
Graphics::TBitmap *pBMP16bit = new Graphics::TBitmap();
pBMP16bit->PixelFormat = pf16bit;
pBMP16bit->Height = nHi;
pBMP16bit->Width = nWe;
int x,y;
Word *ptr;
Word wHiLo;
Byte byHi, byLo;

for (y = 0; y < nHi; y )
{
ptr = (Word *)pBMP16bit->ScanLine[y];
for (x = 0; x < nWe; x )
{
byHi = ((Byte)RGB_565Ary[y*nWe x].rgbtRed << 3) |
((Byte)RGB_565Ary[y*nWe x].rgbtGreen && 0x38) >> 3;
byLo = ((Byte)RGB_565Ary[y*nWe x].rgbtGreen && 0x07) << 5 |
((Byte)RGB_565Ary[y*nWe x].rgbtBlue);
wHiLo = (byHi << 8) | byLo;
ptr[x] = wHiLo;
}
}
Image2->Picture->Bitmap->Assign(pBMP16bit);
}
//---------------------------------------------------------------------------

[/code]
附加檔案:47da0fa0e7ce1_RGB565.rar
編輯記錄
ychong 重新編輯於 2008-03-14 13:41:37, 註解 無‧
ychong
一般會員


發表:1
回覆:1
積分:0
註冊:2005-03-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-03-14 17:32:31 IP:59.120.xxx.xxx 訂閱
各位:
對不起啦~我自爆了
錯誤的地方是在邏輯符號 "&"
我多用了一個,抱歉抱歉~
自己太不小心了

byHi = ((Byte)RGB_565Ary[y*nWe x].rgbtRed << 3) |
((Byte)RGB_565Ary[y*nWe x].rgbtGreen & 0x38) >> 3;
byLo = ((Byte)RGB_565Ary[y*nWe x].rgbtGreen & 0x07) << 5 |
((Byte)RGB_565Ary[y*nWe x].rgbtBlue);


===================引 用 ychong 文 章===================
各位好:
想請問一下RGB 24bit 轉 RGB 16bit 後,顯示出來的顏色不正常
不確定是哪個環節出問題了,請各位幫我解惑,謝謝

RGB565圖例:


下列是我的程式碼與原始檔:

[code cpp]
//---------------------------------------------------------------------------
void __fastcall TMain_Form::Open1Click(TObject *Sender)
{
pBitmap = new Graphics::TBitmap();
TRGBTriple *ptr;
int x,y;
if (OpenPictureDialog1->Execute())
{
try
{
pBitmap->LoadFromFile(OpenPictureDialog1->FileName);
nWe = pBitmap->Width;
nHi = pBitmap->Height;
pBitmap->PixelFormat = pf24bit;
RGB_888Ary = new TRGBTriple[nHi*nWe];
RGB_565Ary = new TRGBTriple[nHi*nWe];
for (y = 0; y < nHi; y )
{
ptr = (TRGBTriple *)pBitmap->ScanLine[y];
for (x = 0; x < nWe; x )
{
RGB_888Ary[y*nWe x] = ptr[x];
RGB_565Ary[y*nWe x].rgbtRed = (Byte)ptr[x].rgbtRed >> 3; // 5-bit red
RGB_565Ary[y*nWe x].rgbtGreen = (Byte)ptr[x].rgbtGreen >> 2; // 6-bit green
RGB_565Ary[y*nWe x].rgbtBlue = (Byte)ptr[x].rgbtBlue >> 3; // 5-bit blue
}
}
Image1->Picture->Bitmap->Assign(pBitmap);
}
catch (...)
{
ShowMessage("Could not load or alter bitmap");
}
delete pBitmap;
}
}
//---------------------------------------------------------------------------

void __fastcall TMain_Form::BitBtn1Click(TObject *Sender)
{
Graphics::TBitmap *pBMP16bit = new Graphics::TBitmap();
pBMP16bit->PixelFormat = pf16bit;
pBMP16bit->Height = nHi;
pBMP16bit->Width = nWe;
int x,y;
Word *ptr;
Word wHiLo;
Byte byHi, byLo;

for (y = 0; y < nHi; y )
{
ptr = (Word *)pBMP16bit->ScanLine[y];
for (x = 0; x < nWe; x )
{
byHi = ((Byte)RGB_565Ary[y*nWe x].rgbtRed << 3) |
((Byte)RGB_565Ary[y*nWe x].rgbtGreen && 0x38) >> 3;
byLo = ((Byte)RGB_565Ary[y*nWe x].rgbtGreen && 0x07) << 5 |
((Byte)RGB_565Ary[y*nWe x].rgbtBlue);
wHiLo = (byHi << 8) | byLo;
ptr[x] = wHiLo;
}
}
Image2->Picture->Bitmap->Assign(pBMP16bit);
}
//---------------------------------------------------------------------------

[/code]
編輯記錄
ychong 重新編輯於 2008-03-14 17:34:33, 註解 無‧
系統時間:2024-03-29 8:39:20
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!