RGB 24bit 轉 RGB565 16bit |
缺席
|
ychong
一般會員 ![]() ![]() 發表:1 回覆:1 積分:0 註冊:2005-03-15 發送簡訊給我 |
各位好:
想請問一下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 13:41:37, 註解 無‧
|
ychong
一般會員 ![]() ![]() 發表:1 回覆:1 積分:0 註冊:2005-03-15 發送簡訊給我 |
各位:
對不起啦~我自爆了 錯誤的地方是在邏輯符號 "&" 我多用了一個,抱歉抱歉~ 自己太不小心了 ![]() 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, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |