Search code examples
delphidelphi-xevcl

Delphi XE7 TBitBtn Image wrong Displayed at run time


I have a project developed with Delphi 7 and VCL, that compiles and works with the new Delphi XE7 without any modification, the only issue that I'm experiencing is that the Glyph image of the TBitBtn is wrong displayed(as you can see the color and the position are not the same) at run time despite is well displayed at design time .

Design Time :

TBitBtn Image Design Time

RunTime :

tBitBtn Image Run Time

What can cause the problem ?

NOTE

With the old Delphi 7 I don't have this issue : the image is correctly displayed both at design and run time .

Following the first 3 lines of the Glyph data in the dfm :

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

that it is the same in Delphi 7 and Delphi XE7.

If I click on the Glyph property of TBitBtn I can see the image(the wrong one) in the dialog and if I confirm with OK, the IDE changes the Glyph property in the DFM files in this way(diff output) :

     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
-      D900FBF9F900FBFAFA00FCFB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      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}

At this link there is the complete DFM file that present the problem .


Solution

  • I decided to enter another answer instead of editing the previous, because the first answer was given by the information available at that time, and although not the correct one, may serve a purpose. In the following is an answer I believe is the correct one.

    The short answer

    Most of the images had partly corrupt headers. The reason might be in the original images, conversion from other image formats or in Delphi7, but I couldn't set aside enough time to debug the code. If I had the time I would look at TBitmap.ReadDIB and TBitmap.Changed. The error surfaces in Delphi XE7 (possibly also in earlier version) because some changes have been made in above mentioned methods.

    The cure is to redraw the images in a decent image editor.

    The longer answer

    I came to the corrupt images conclusion by investigating Glyph.Data of a couple of TBitBtn controls in the .dfm file. Those that seem to be wrong have similar errors in the bitmap headers. Let's look at one of them:

    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
    

    The structure of the whole Glyph.Data is

    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)
    

    The problems are:

    1. Glypf.BitmapSize is 13366 but bmpfh.bfSize reports it to be 14390, a difference of 1024 bytes.
    2. Offset of pixel array is reported to be 2102. Subtracting size of bmfh (14) and bmih (40) leaves 2048 bytes for the colortable, bmiColors. Should be 1024.
    3. The actual image data in the .dfm is 1024 bytes for the color table, bmiColors. When the image is read in XE7 the erroneous bfOffBits offsets the beginning of the pixel data and thus we see the shift in the image and its colors.
    4. When the image is 'reloaded' by opening the image editor the error is repeted with already erroneous data and the image and color shifts are exaggerated.

    As said above, the cure is to redraw the images. One could of course also attempt to change the .dfm files directly.