How I can load a Png image from file which have another extension?

Go To StackoverFlow.com

5

I'm using a TImage component to load some png images, but some of them have the .imp extension. I add the Vcl.Imaging.pngimage unit to my code and I'm using this code to load the images

 if OpenDialog1.Execute then
  Image1.Picture.LoadFromFile(OpenDialog1.FileName);

But when the LoadFromFile procedure is executed a exception is raised

Unknown picture file extension (.imp)

these images (.imp) are png files generated by an extenal app and are located in a read-only folder, so rename these files is not a option, the question is How I can load a Png image in a TImage component from a file which have another extension?

2012-04-04 21:37
by Salvador
load it to a stream and then load the image from tha - Tony Hopkinson 2012-04-04 21:49


14

you must register the file format first using the TPicture.RegisterFileFormat method

Try this

TPicture.RegisterFileFormat('imp','imp (png) image file',TPngImage);
2012-04-04 21:39
by RRUZ
Ads