為什麼pixel值用 byte存跟用integer存,值會不同?? |
答題得分者是:seaturn99
|
CPTL
一般會員 發表:2 回覆:1 積分:0 註冊:2004-09-06 發送簡訊給我 |
我在學校修一門叫數位影像處理的課
老師要求我們寫程式實作
其中我發現到,每個piexl值我用byte值存跟用integer值存,其結果是不同的
我知道byte是用8bit來表示
integer是用32ibt來表示
可是怎麼同樣的資料量,為什麼用8bit表示是正常,
用成32表來表示就錯了呢?
例如:
temp := Image1.Canvas.Pixels[1,1]; //其中temp是byte型態
ShowMessage('temp is ' IntToStr(temp)); //顯示 temp is 160 i := Image1.Canvas.Pixels[1,1]; //其中 i 是integer型態
ShowMessage('i is ' IntToStr(i)); //顯示 i is 10526880 很明顯地用 i 來存是錯的,可是這是為什麼呢?
我同學用的是BCB,他們用int來存pixel值,就是很正常的咧?
另外,有沒有什麼方法能把pixel值也存成integer型態呀? 懇請各位前輩給小弟一點指教,謝謝~
|
seaturn99
版主 發表:69 回覆:427 積分:214 註冊:2003-08-25 發送簡訊給我 |
CPTL 您好: 請參考 Delphi Online Help 查 key word : TColor Image1.Canvas.Pixels[1,1]; 傳回的是 TColor Type 節錄 Online Help :
If you specify TColor as a specific 4-byte hexadecimal number instead of using the constants defined in the Graphics unit, the low three bytes represent RGB color intensities for blue, green, and red, respectively. The value $00FF0000 (Delphi) or 0x00FF0000 (C ) represents full-intensity, pure blue, $0000FF00 (Delphi) or 0x0000FF00 (C ) is pure green, and $000000FF (Delphi) or 0x000000FF (C ) is pure red. $00000000 (Delphi) or 0x00000000 (C ) is black and $00FFFFFF (Delphi) or 0x00FFFFFF (C ) is white. If the highest-order byte is zero, the color obtained is the closest matching color in the system palette. If the highest-order byte is one ($01 or 0x01), the color obtained is the closest matching color in the currently realized palette. If the highest-order byte is two ($02 or 0x02), the value is matched with the nearest color in the logical palette of the current device context. 所以您利用 integer 或 TColor 接回來的值是 RGB ,再仔細分析傳回值...
160 = A0 , 10526880 = A0A0A0 ... 所以利用 byte 傳回的值,是 RGB 值被截斷的結果... ----
我只會兩件事,這也不會,那也不會 眼見不一定為真
----
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |