2014-12-28 46 views
0

我有一個項目與德爾福7和VCL開發,編譯和新的德爾福XE7工作沒有任何修改,我遇到的唯一問題是,字形圖像儘管在設計時很好地顯示TBitBtn在運行時顯示錯誤(,因爲您可以看到顏色和位置不一樣)。德爾福XE7 TBitBtn圖像錯誤在運行時顯示

設計時間

TBitBtn Image Design Time

運行時間

tBitBtn Image Run Time

什麼會導致什麼問題?

注意

隨着老德爾福7,我沒有這個問題:圖像正確顯示無論是在設計和運行時間。

繼前3行中的DFM字形數據的:

Glyph.Data = { 
    36050000424D3605000000000000360400002800000010000000100000000100 
    080000000000000100000000000000000000000100000000000000164900001C 
    4D0000275700003C7100003D6E00004483000046760000467B0000548C00005B 
    ... 

,它是在Delphi 7和Delphi XE7相同。

如果點擊TBitBtn的Glyph屬性,我可以在對話框中看到圖像(錯誤的),如果我用OK進行確認,IDE會以這種方式更改DFM文件中的Glyph屬性(diff輸出) :

 Glyph.Data = { 
-  36340000424D3638000000000000360800002800000040000000400000000100 
-  1800000000000030000000000000000000000001000000000000724242007B47 
-  47007D4849007E4C4B00804C4C0081524F008155500083535200845754008458 
-  56008459590085525200855B5700875D58008B6260008B6361008B6362008C65 
-  63008C6664008D615C008D6665008D6766008E5A5A008F696800906B6A00916C 
-  6B00935F5F00936F6E0094616100946F6F00957170009773730097747400986A 
-  6600997777009C7B7B009E7D7D009F6B6B00A06C6C00A1818100A26E6E00A37B 
-  7400A3817600A4707000A6727200A67C7600A6867A00A7737300A7877B00A983 
-  7B00AA8E8E00AB8C7F00AC8A7F00AC8F8F00AE918300AE939300AF959500B190 
-  8400B1958700B2999900B37F7F00B49B9B00B79F9F00B8848400B89FA000BA86 
-  8600BB878700BBA5A500BC888800BE8A8A00C08B8B00C18D8D00C1A89700C2AD 
-  AD00C38F8F00C4A69800C5919100C7929200C8939300C9949400CA959500CB95 
-  9600CB969600CCA79D00CDA49D00CF999A00CFBBA700D09D9C00D0BCA700D0BC 
-  A800D0BDA900D19C9C00D1BDA900D29F9E00D39E9E00D3AAA300D49F9F00D4B2 
-  A700D4C1AC00D4C1AD00D4C2AD00D4C5C500D6ABA500D6C8C800D7ADA700D7C5 
-  B000D8AFA800D8C7B000D8C7B100D8CACB00D9B1A900D9BEAE00DAB2AA00DAB3 
-  AA00DAB3AB00DACAB300DACECE00DBA6A600DBB4AB00DBB4AC00DBB5AC00DBB6 
-  AC00DBC1B000DBCBB400DBCCB400DCB6AC00DCB6AD00DCCCB400DDB7AE00DDB8 
-  AE00DDCDB600DEADAB00DEBAAF00DEBBB000DED4D400DFBCB100DFBDB100DFBD 
-  B200DFBEB200DFD0B900E0ADAC00E0B4AE00E0BDB200E0BEB200E0BFB300E0D2 
-  BA00E1ADAD00E1C0B400E1C1B400E1D1BA00E2BAB200E2C3B500E3C4B600E3C5 
-  B700E3C7B700E4C5B700E4C7B700E4C7B800E4C8B800E4C9B900E5C9B900E5CA 
-  B900E5CABA00E5CBBA00E6CCBC00E6DDDD00E7CEBD00E7D7C000E8B8B500E8B9 
-  B600E8BAB600E8C3B900E8CFBD00E8CFBE00E8D0BE00E8D0BF00E8D1BF00E9C7 
-  BB00E9D1BF00E9D2BF00E9D2C000E9D3C000EAC7BC00EBD5C200ECB9B800ECCE 
-  BF00ECD4C200ECD7C300ECD8C300ECD8C400ECD9C400ECE6E600EDD9C400EDD9 
-  C500EDDAC500EDDBC500EED3C300EEDBC700EEDCC700EEDDC800EFCCC100EFDD 
-  C800F0BEBC00F0DFC900F0E0CA00F0E1CA00F0E1CB00F1E1CB00F1E2CB00F1E2 
-  CC00F1E3CC00F1EDED00F2C4C100F2C9C200F2DDCA00F2E3CC00F2E4CC00F2E4 
-  CD00F2E5CD00F2EDEE00F3E5CD00F3E5CE00F3E6CE00F3EFEF00F4F0F000F4F0 
-  F100F5E5CF00F5F2F200F6EBD200F6ECD300F6F3F400F7ECD300F7EDD300F7ED 
-  D400F7EED400F8EDD400F8EED400F8EED500F8EFD500F8F0D500F8F6F600F9EF 
-  D500F9F0D600F9F1D600F9F1D700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FFFFFFFFFFF 
-  FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 
-  FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDFCFCD3C5C5C7B5B5D7CBCBE4DC 
-  DCEFEAEAF7F5F5FDFCFCFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 
+  36300000424D3634000000000000360400002800000040000000400000000100 
+  1800000000000030000000000000000000000001000000000000FFFFFFFFFFFF 
     FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 
     FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 
     FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 
@@ -469,7 +403,43 @@ object Form1: TForm1 
     FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 
     FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 
     FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 
-  FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF} 
+  FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000000000000000 
+  0000000000000000000000000000000000000000000000000000} 

this link有一個完整的DFM文件提出的問題。

+0

是什麼類型的圖像?基於快速觀察,似乎某些數據損壞發生在運行時或數據未正確加載。如果你看圖片,看起來顏色通道可能已經被打亂了。綠色似乎被藍色,藍色和紅色所取代,就好像顏色通道將被移動一個字節一樣。圖像位置偏移也可能是由於數據損壞或不正確的數據處理造成的,就好像文件頭未正確解析並且程序可能將其視爲圖像數據一樣。 – SilverWarior

+0

請將圖像顯示爲您在D7中加載到BitBtn中的原始.bmp文件。在'Glyph.Data = {' –

+0

我認爲原始圖像是一個PNG文件(可能轉換成BMP)文件後,從.dfm(包括D7和XE7)中複製出三行十六進制值,我不能說當然,因爲我從以前的開發者繼承了這個項目,而且我沒有原始的導入圖片文件......無論如何,我已經用一些有用的信息更新了這個問題。謝謝。 – aleroot

回答

1

我決定進入的不是編輯之前的另一個答案,因爲第一次的答案被給出的信息當時可用,雖然不是正確的,但可以達到目的。以下是我認爲是正確答案的答案。

簡短的回答

大部分圖片有部分損壞的頭。原因可能在於原始圖像,從其他圖像格式或Delphi7轉換,但我不能留出足夠的時間來調試代碼。如果我有時間,我會查看TBitmap.ReadDIB和TBitmap.Changed。 Delphi XE7中的錯誤表面(可能也是早期版本),因爲在上述方法中進行了一些更改。

治癒的方法是在一個體面的圖像編輯器中重繪圖像。

較長的答案

我通過調查在.DFM文件一對夫婦TBitBtn控制的Glyph.Data來到腐敗圖像的結論。那些似乎錯誤的位圖標題中有類似的錯誤。讓我們來看看其中的一個:

ToolButton1: TBitBtn 

    Glyph.Data = { 
     36340000424D3638000000000000360800002800000040000000400000000100 
     1800000000000030000000000000000000000001000000000000724242007B47 
     ...} 
Glyph.BitmapSize  = 13366 
bmfh.bfType   = BM 
bmfh.bfSize   = 14390 
bmfh.bfReserved1  = 0 
bmfh.bfReserved2  = 0 
bmfh.bfOffBits  = 2102 
bmih.biSize   = 40 
bmih.biWidth   = 64 
bmih.biHeight  = 64 
bmih.biPlanes  = 1 
bmih.biBitCount  = 24 
bmih.biCompression = 0 
bmih.biSizeImage  = 12288 
bmih.biXPelsPerMeter = 0 
bmih.biYPelsPerMeter = 0 
bmih.biClrUsed  = 256 
bmih.biClrImportant = 0 

整個Glyph.Data的結構

Glyph.BitmapSize (size 4 bytes), managed by Delphi 
BITMAPFILEHEADER (size 14 bytes) 
BITMAPINFOHEADER (size 40 bytes) 
bmiColors array (size, when used, should be biClrUsed * SizeOf(TRGBQuad) or 1024 in this case) 
bmBits (pixel values, either indexes to bmiColors or direct RGB(A) color values) 

的問題是:

  1. Glypf.BitmapSize是13366,但bmpfh.bfSize其報告是14390,相差1024字節。
  2. 像素陣列的偏移量報告爲2102。減去bmfh(14)和bmih(40)的大小會爲colortable bmiColors留下2048個字節。應該是1024.
  3. .dfm中的實際圖像數據對於顏色表bmiColors爲1024字節。當在XE7中讀取圖像時,錯誤的bfOffBits會偏移像素數據的開始,因此我們會看到圖像及其顏色的偏移。
  4. 當通過打開圖像編輯器重新加載圖像時,錯誤會被錯誤的數據所淹沒,並且圖像和顏色偏移被誇大。

如上所述,治癒方法是重新繪製圖像。當然也可以嘗試直接更改.dfm文件。

+0

有沒有免費的工具來快速重繪圖像?謝謝。 – aleroot

+0

@aleroot不是我所知道的,但我已經更正了圖像。在Embarcadero論壇尋找給你的信息。 –

3

它似乎是NumGlyphs屬性與圖像中實際雕文數量之間的不匹配。 我無法解釋爲什麼你在Delphi 7中沒有這個問題,但是我可以在XE7中用例如一個64x64 TBitBtn,256像素寬的圖像,如果我設置了NumGlyphs := 3,它有四個字形(每個64像素寬)。

在設計時,會顯示第一個字形。每個字形(256格3)的像素計算將會給出85像素的寬度。但這並不重要,因爲我們從第一個像素開始看到第一個字形。

在運行時,它看起來按鈕處於禁用狀態(Enabled=false),因此它顯示第二個字形,但由於NumGlyphs中的值錯誤,它顯示的像素以左85向前開始,因此從左邊切下21像素,將第三個字形中的21個像素放到視圖中。


您可以用下面的分手

Glyph.Data = { 
    36C00000424D36C0000000000000360000002800000000010000400000000100 
    18000000000000C00000C40E0000C40E00000000000000000000F0F0F0F0F0F0 
    F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0 
    ... 

解釋爲

offs 36C00000 file size = 0x0000C036 = 49206 
0000 424D  'BM' signature 
0002 36C00000 file size 
0006 0000  reserved 2 bytes 
0008 0000  reserved 2 bytes 
000A 36000000 pixel array offset = 0x36 = 54 
000E 28000000 BITMAPINFOHEADER size 0x28 = 40 
0012 00010000 bitmap width 0x0100 = 256 
0016 40000000 bitmap height 0x0040 = 64 
001A 0100  num of color planes = 1 
001C 1800  num of bits per pixel = 24 
001E 00000000 compression method (0 = none) 
0022 00C00000 raw bitmap data size 49152 = 256 x 64 x 3 bytes 
0026 C40E0000 horizontal resolution (pix per meter) 3780/m 
002A C40E0000 vertical resolution (pix per meter) 3780/m 
002E 00000000 num of colors in color palette or 0 for default 2^n 
0032 00000000 num of important colors used, or 0 for every color is important 
pixel array follows 
0036             F0F0F0F0F0F0 
003C F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0 

德爾福比較Glyph.Data年初在.DFM文件(D7和XE7)在實際的.bmp文件前添加自己的大小。偏移量是從 'BM' 簽署後的額外數據

的三條線是在D7和XE7相同解釋


編輯:

Glyph.Data = { 
36050000 File size 1334 
424D  'BM' 
36050000 file size 1334 
0000 
0000 
36040000 1078 pix arr offset 
28000000 40 header size 
10000000 16 bmp width 
10000000 16 bmp height 
0100  1 color planes 
0800  8 bits per pix 
00000000 no compression 
00010000 256 raw bitmap data size 
00000000 0 horiz pix per meter 
00000000 0 vert ppm 
00010000 256 colors in palette 
00000000 all colors important 
00164900001C .... 

並不真正適合您張貼的圖像,在灰色邊框內爲64 x 64,並具有1628種獨特的顏色。

但是真正讓我困惑的是當你點擊Glyph屬性時的變化。根據差異列表,三個首先替換的( - )行根本不匹配上述三行。分解如下:

{ 
36340000 13366 
424D  'BM' 
36380000 14390 
0000 
0000 
36080000 2102 pix arr offset 
28000000 40 header size 
40000000 64 width 
40000000 64 height 
0100 
1800 
00000000 
00300000 12288 raw bmp data size 
00000000 
00000000 
00010000 256 colors in palette 
00000000 
724242007B47 ...} 

現在,這匹配大小(64 x 64),但不是顏色數量。無論如何其餘的是腐敗和無用的數據。去搞清楚。我能想到的唯一解決方案是替換圖像。由於我已經在我的編輯器中發佈了您的張貼圖片,因此我製作了一張三倍圖像(正常,禁用,按下)192 x 64,並在D7和XE7中進行了測試,並且對我而言效果不錯。

這裏,因爲你原來的丟失,作爲友好季節禮物:-)

enter image description here

+0

這是否解釋顏色偏移? –

+0

@Sertac不,不是這樣的。 SilverWarior可能是正確的關於損壞的數據,然後也可以涵蓋圖像的轉變。我希望OP能回答S的評論。我會加我自己的q。 –

+0

我已經用更多信息更新了答案...感謝您的幫助。 – aleroot