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

請問用pixel[i][j]的值取rgb

尚未結案
ddaken
一般會員


發表:39
回覆:33
積分:19
註冊:2005-01-21

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-08-15 00:06:23 IP:61.229.xxx.xxx 未訂閱
請問各位大大 我想取rgb的值~我已看過有人用     r = (c & 0x000000FF);     g = ((c & 0x0000FF00) >> 8);     b = ((c & 0x00FF0000) >> 16); 來取值 可是我如果把程式改成用ScanLine來增加速度 是不是不可以這樣用? 因為我的程式所跑出來的都是紅色的~  
 
void __fastcall TForm1::ShowRGB1Click(TObject *Sender)
{
Byte *ptr;    Graphics::TBitmap *Bmp = new Graphics::TBitmap();
Bmp->Assign(Image1->Picture->Bitmap);
Bmp->PixelFormat=pf24bit;
Image2->Picture->Bitmap=Bmp;
Image3->Picture->Bitmap=Bmp;
Image4->Picture->Bitmap=Bmp;        for(int j=0;jHeight;j  )
{
 ptr = (Byte *)Bmp->ScanLine[j];
 for(int i=0;iWidth;i  )
 {
  Image2->Picture->Bitmap->Canvas->Pixels[i][j]=(TColor) ptr[i*3];
  Image3->Picture->Bitmap->Canvas->Pixels[i][j]=(TColor) ptr[i*3 1];
  Image4->Picture->Bitmap->Canvas->Pixels[i][j]=(TColor) ptr[i*3 2];
}
}    }    
發表人 - ddaken 於 2005/08/15 00:07:34
IORIS
一般會員


發表:15
回覆:21
積分:7
註冊:2005-01-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-08-15 11:01:02 IP:59.104.xxx.xxx 未訂閱
你好! 希望下面這段程式碼能對你有幫助
  Graphics::TBitmap *Bmp = new Graphics::TBitmap();  
  Bmp->Assign(Image1->Picture->Bitmap);  
  Byte *ptr;
  int R,G,B;
  for (int i=0;iHeight;i  )
   {
    ptr=(Byte *)Bmp->ScanLine[i]; 
    for(int j=0;jWidth;j  )     
     {
      B=ptr[3*j];
      G=ptr[3*j 1];
      R=ptr[j*3 2];
     }
   }
發表人 - ioris 於 2005/08/15 11:06:11
RedSnow
版主


發表:79
回覆:1322
積分:845
註冊:2003-12-15

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-08-15 14:55:51 IP:59.115.xxx.xxx 未訂閱
ddaken 您好:    我看您似乎是想要將 Image1 原圖分解成三色,並分別顯示於另外三個 Image 物件上,如果我猜得沒錯,那麼您可以參考一下下列的處理方式:
// 宣告三個暫存用的 Bitmap
Graphics::TBitmap *Bmp2 = new Graphics::TBitmap();
Graphics::TBitmap *Bmp3 = new Graphics::TBitmap();
Graphics::TBitmap *Bmp4 = new Graphics::TBitmap();    // 先將 Image1 內容複製給三個暫存的 Bitmap
Bmp2->Width  = Image1->Picture->Bitmap->Width;
Bmp2->Height = Image1->Picture->Bitmap->Height;
Bmp2->Canvas->Draw(0, 0, Image1->Picture->Bitmap);
Bmp2->PixelFormat = pf24bit;    Bmp3->Width  = Image1->Picture->Bitmap->Width;
Bmp3->Height = Image1->Picture->Bitmap->Height;
Bmp3->Canvas->Draw(0, 0, Image1->Picture->Bitmap);
Bmp3->PixelFormat = pf24bit;    Bmp4->Width  = Image1->Picture->Bitmap->Width;
Bmp4->Height = Image1->Picture->Bitmap->Height;
Bmp4->Canvas->Draw(0, 0, Image1->Picture->Bitmap);
Bmp4->PixelFormat = pf24bit;    // TRGBTriple 是一個結構資料,使用它來處理以提高易讀性
TRGBTriple *ptr2;
TRGBTriple *ptr3;
TRGBTriple *ptr4;    for (int line=0; lineHeight; line  ) {
    TRGBTriple *ptr2 = (TRGBTriple *)Bmp2->ScanLine[line];
    TRGBTriple *ptr3 = (TRGBTriple *)Bmp3->ScanLine[line];
    TRGBTriple *ptr4 = (TRGBTriple *)Bmp4->ScanLine[line];
    for (int pixel=0; pixelWidth; pixel  ) {
        // 保留紅色值
        ptr2[pixel].rgbtGreen = 0;
        ptr2[pixel].rgbtBlue  = 0;            // 保留綠色值
        ptr3[pixel].rgbtRed   = 0;
        ptr3[pixel].rgbtBlue  = 0;            // 保留藍色值
        ptr4[pixel].rgbtRed   = 0;
        ptr4[pixel].rgbtGreen = 0;
    }
}    // 將處理過後的暫存 Bitmap 設給對應的另三個 Image 物件
Image2->Picture->Bitmap->Assign(Bmp2);
Image3->Picture->Bitmap->Assign(Bmp3);
Image4->Picture->Bitmap->Assign(Bmp4);    // 清除掉暫存的 Bitmap
delete Bmp2;
Bmp2 = NULL;
delete Bmp3;
Bmp3 = NULL;
delete Bmp4;
Bmp4 = NULL;
7 天天敲鍵盤 v 時時按滑鼠 8 發表人 - RedSnow 於 2005/08/15 15:29:57
系統時間:2024-05-04 18:24:56
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!