Search code examples
delphidelphi-xe6

How to put PNG into TImageList?


I have a PNG image that i'm trying to load into a TImageList at design-time:

enter image description here

I have an image list, which i then try to open my png:

enter image description here

Once added, the image that appears is not correct:

enter image description here

What steps in opening a file am i missing?

Edit: Lets try some more files

enter image description here enter image description here

enter image description here enter image description here

enter image description here enter image description here

Edit: More settings

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Any other variations anyone would like to see?


Solution

  • The issue was that I was using a function contained in the GraphicEx library:

    procedure Stretch(NewWidth, NewHeight: Cardinal; Filter: TResamplingFilter; 
          Radius: Single; Source: TBitmap);
    

    The call to this function is abstracted away inside a ResizeGraphic helper function.

    The problem is that GraphicEx also has it's own PNG implementation:

    TPNGGraphic = class(TGraphicExGraphic)
    

    which is then registered at runtime as an available file format:

    initialization
    RegisterFileFormat('png', gesPortableNetworkGraphic, '',
          [ftRaster], False, True, TPNGGraphic);
    

    Enter Custom Controls

    We use some custom Delphi components.

    Some of these components directly or indirectly import a reference to GraphicEx. This then means that GraphicEx is taking over handling of the PNG file type away from whatever class exists inside the IDE at design.

    The solution was to define away all the RegisterFileFormat lines in the initialization section of GraphicEx.pas

    {$ifdef PortableNetworkGraphic}
    RegisterFileFormat('png', gesPortableNetworkGraphic, '', [ftRaster], False, True, TPNGGraphic);
    {$endif}
    

    and then re-build all my runtime and design-time packages.

    Once that was done, and the IDE restarted:

    enter image description here

    Note: Any code released into public domain. No attribution required.