Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 835
Salvador Avatar asked Apr 04 '12 21:04

Salvador


1 Answers

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

Try this

TPicture.RegisterFileFormat('imp','imp (png) image file',TPngImage);
like image 72
RRUZ Avatar answered Oct 20 '22 07:10

RRUZ