views:

292

answers:

2

Running Turbo Delphi Pro.

I'm using TImage to display a png image.

When I restart Delphi and load the dpr file, TImage is still there, but the picture is lost, requiring a reload of the picture before compiling.

At first I thought it's a path issue, so I loaded the picture from the same directory as the dpr, but it didn't help.

What else can I try?

+1  A: 

Try this:

  • Open your project and your Form with the PNG.
  • (Re)Load the PNG image.
  • Save and close your Form.
  • With a text editor, load your Form DFM
  • I bet you don't have a big binary in your TImage object, because the PNG content has not been saved.

Bottom line, you'd have to include it as a resource and load it dynamically at runtime.

François
+1  A: 

I ran into this problem as well with D2006. The solution I used is similar to François'.

I have a TPngImageCollection component that I collect all the images in at design time. You will need to find unit PngImageList off the web. The TPngImageCollection component has the advantage that you can have a collection of PNG images of differing sizes.

At run-time on startup, I assign the TImages from each of the collection members:

Image1.Picture.Assign (ImageCollection.Items [0].PNGImage) ;
Image2.Picture.Assign (ImageCollection.Items [1].PNGImage) ;
Image3.Picture.Assign (ImageCollection.Items [2].PNGImage) ;
etc

Bingo - you can produce your PNG originals with alpha transparency (I use PhotoPlus 6.0 from Serif - free and very capable) and show them in a TImage.