我有一个用Delphi 7和VCL开发的项目,无需任何修改即可编译和使用新的Delphi XE7,我遇到的唯一问题是TBitBtn的Glyph图像显示错误(尽管在设计时很好地显示,但在运行时你可以看到颜色和位置不一样。
设计时间:
运行时间:
可能导致问题的原因是什么?
注意
使用旧的Delphi 7我没有这个问题:图像在设计和运行时都正确显示。
在dfm中的前三行字形数据之后:
Glyph.Data = {
36050000424D3605000000000000360400002800000010000000100000000100
080000000000000100000000000000000000000100000000000000164900001C
4D0000275700003C7100003D6E00004483000046760000467B0000548C00005B
...
在Delphi 7和Delphi XE7中它是相同的。
如果我单击TBitBtn的Glyph属性,我可以在对话框中看到图像(错误的图像),如果我确认,则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
- D500F9F0D600F9F1D600F9F1D700F9F7F700FAF2D700FAF8F800FAF9F900FBF4
- D900FBF9F900FBFAFA00FCFBFB00FDFDFD00FEFEFE00FFFFFF00FFFFFFFFFFFF
- FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF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FF
+ 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 :(得分:3)
NumGlyphs
属性与图像中实际的字形数量之间似乎不匹配。
我无法解释为什么你在Delphi 7中没有这个问题,但我可以在XE7中创建相同的效果,例如:一个64x64 TBitBtn,一个256像素宽的图像,如果我设置NumGlyphs := 3
,它有四个字形(每个64像素宽)。
在设计时,会显示第一个字形。每个字形(256 div 3)的像素计算将给出85像素的宽度。但这并不重要,因为我们从第一个像素开始看到第一个字形。
在运行时,似乎按钮处于禁用状态(Enabled=false
),因此它显示第二个字形,但由于NumGlyphs中的值错误,它显示以向左85向前开始的像素,因此切割21像素从左边开始,将第三个字形的21个像素放到视图中。
您可以将.dfm文件中的Glyph.Data的开头(在D7和XE7中)与以下分解进行比较
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
Delphi在实际的.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中进行了测试,并且对我来说效果很好。
在这里,由于您的原件丢失,作为友好的季节礼物: - )
答案 1 :(得分: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)
问题是:
bmpfh.bfSize
报告为14390,相差1024字节。 如上所述,治愈方法是重绘图像。当然也可以尝试直接更改.dfm文件。