RGB的問題 |
尚未結案
|
harisan3
一般會員 發表:6 回覆:11 積分:3 註冊:2004-12-10 發送簡訊給我 |
我自己寫了兩個TImage to 陣列,跟陣列 to TImage的副程式,但是執行陣列 to TImage後卻發現 RGB跟我原來的不一樣,不知道我這樣寫哪裡有問題?
typedef struct tagRGBValue { BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; } RGBValue; void TImage2ImageMatrix(TImage *srcImage,Byte ImageMatrix[240][320]) { Byte *ptr; srcImage->Height =240; srcImage->Width=320; srcImage->Picture->Bitmap->PixelFormat = pf24bit; for (int row = 0; row < srcImage->Height; row ) { ptr = (Byte *)srcImage->Picture->Bitmap->ScanLine[row]; for(int col = 0; col |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
harisan3
一般會員 發表:6 回覆:11 積分:3 註冊:2004-12-10 發送簡訊給我 |
|
RedSnow
版主 發表:79 回覆:1322 積分:845 註冊:2003-12-15 發送簡訊給我 |
harisan3 您好: 問題出在資料型態,我將您的程式改寫如下,經測試後可以正確運作,您參考看看吧:
typedef struct tagRGBValue { BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; } RGBValue; DWORD ImageMatrix[240][320]; void TImage2ImageMatrix(TImage *srcImage, DWORD ImageMatrix[240][320]) { srcImage->Height = 240; srcImage->Width = 320; srcImage->Picture->Bitmap->PixelFormat = pf24bit; for (int row = 0; row < srcImage->Height; row ) { // 既然 ImageMatrix2TImage() 都使用 ScanLine 了,此處也改成相同處理方式 RGBValue *Pixel = (RGBValue *) srcImage->Picture->Bitmap->ScanLine[row]; for(int col = 0; col < srcImage->Width; col ) ImageMatrix[row][col]=(TColor)RGB(Pixel[col].rgbRed, Pixel[col].rgbGreen, Pixel[col].rgbBlue); } } void ImageMatrix2TImage(TImage *DestImage, DWORD ImageMatrix[240][320]) { Graphics::TBitmap *Bmp = new Graphics::TBitmap(); Bmp->Assign(DestImage->Picture->Bitmap); Bmp->PixelFormat = pf24bit; Bmp->Height = 240; Bmp->Width = 320; for (int Row = 0; Row < Bmp->Height; Row ) { RGBValue *Pixel = (RGBValue *) Bmp->ScanLine[Row]; for (int Col = 0; Col < Bmp->Width; Col ) { Pixel[Col].rgbRed = GetRValue(ImageMatrix[Row][Col]); Pixel[Col].rgbGreen = GetGValue(ImageMatrix[Row][Col]); Pixel[Col].rgbBlue = GetBValue(ImageMatrix[Row][Col]); } } DestImage->Picture->Bitmap->Assign(Bmp); delete Bmp; }7 天天敲鍵盤 v 時時按滑鼠 8 |
harisan3
一般會員 發表:6 回覆:11 積分:3 註冊:2004-12-10 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |