請問這樣使用scanline的方法哪裡錯了呢? |
答題得分者是:taishyang
|
leochen1204
一般會員 發表:10 回覆:14 積分:4 註冊:2008-11-06 發送簡訊給我 |
我想要在Image1中顯示Array的內容(Array裡是影像資料)
就寫了一段程式測試, 我原本以為會出現灰灰的色塊. 因為我Array裡都放123 但是最後只看到一條斜斜的線, 由左上到右下... 而且是綠色的... 請問是哪裡錯了呢?? [code cpp] int i; Graphics::TBitmap *pBitmap = new Graphics::TBitmap(); pBitmap->PixelFormat=pf8bit; pBitmap->Width=600; pBitmap->Height=600; Byte *ptr1,test[600]; for(i = 0; i < 600; i ) //測試Array test[i]=123; for(i = 0; i < points; i ) { ptr1=(Byte*) pBitmap->ScanLine[i]; ptr1[i]=test[0]; } Image1->Picture->Bitmap->Assign(pBitmap); Image1->Refresh(); [/code] |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
http://delphi.ktop.com.tw/board.php?cid=168&fid=921&tid=55371
連結中有相關的討論. 要修改調色盤來綠色的問題 而斜線的原因是因為ScanLine是用在一行一行的像素. void __fastcall TForm1::Button1Click(TObject *Sender) { // 定義調色盤結構 typedef struct { TLogPalette lpal; TPaletteEntry dummy[256]; } LogPal; // 建立灰階調色盤 LogPal GrayPalette; GrayPalette.lpal.palVersion = 0x300; GrayPalette.lpal.palNumEntries = 256; for(int Index = 0; Index < 256; Index ){ GrayPalette.lpal.palPalEntry[Index].peRed = (unsigned char)Index; GrayPalette.lpal.palPalEntry[Index].peGreen = (unsigned char)Index; GrayPalette.lpal.palPalEntry[Index].peBlue = (unsigned char)Index; GrayPalette.lpal.palPalEntry[Index].peFlags = (unsigned char)0; } Graphics::TBitmap *pBitmap = new Graphics::TBitmap(); pBitmap->Width = 600; pBitmap->Height = 600; pBitmap->PixelFormat = pf8bit; pBitmap->Palette = CreatePalette((const tagLOGPALETTE*)&GrayPalette.lpal); Byte *ptr1,test[600]; memset(test, 123, sizeof(test)); for(int i = 0; i < pBitmap->Height; i ){ ptr1=(Byte*) pBitmap->ScanLine[i]; for (int j=0; j ptr1[j]=test[0]; } } Image1->Picture->Bitmap->Assign(pBitmap); Image1->Refresh(); } |
leochen1204
一般會員 發表:10 回覆:14 積分:4 註冊:2008-11-06 發送簡訊給我 |
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
不知道您有沒有看完該討論串
裡面提到 經過測試發現,我用的圖(包括從網頁上copy下您使用的圖(.bmp))都不是256色。 於是我就改用Borland提供的256色圖檔,果然疑似的靈異現象出現了,但也有了較合理的解釋。 我參考TBitmap對Palette的說明,試驗發現在256色(含)以下時,調色盤才會被參考; 而在更高顏色格式時,則直接引用pixel的內容轉換成該點的顏色,不需參考調色盤。 ===================引 用 leochen1204 文 章=================== 那如果是用在32bit的色彩的話, 仍需要建立調色盤嗎 ? |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |