Re: Reading images from a file

Posted by Peter on March 14, 2007

In Reply to Reading images from a file posted by Yair Eshel on March 12, 2007

: I now have a form, using a TImage objects, that I want changed. Looking at the form code, I found out the worse I could have imagined: It's not reading the jpg from a file, but converted it to, what I suspect, a A bmp, and translated it into hex. Now the project I'm working on need to create a series of more then 100 images, that I need to find a way to create dynamically, as it is developed for wide usage. I don't have a problem with the imaged "hard coded" as long as there's a way to create the source without actually linking an image one by one.
: The way I see it there are two solutions, that I hope you'll be able to direct me to:
: 1. Some delphi lib will allow me to link a jpg, or if possible a gif image to a form object.
: 2. Some application, preferably command line application that can run on linux, that will allow me to create a text file with the image data. moving it into the delphi code will not be a hard task for me.

If I understand you well, you want to show different images in a TImage component, and not load them at design-time. Correct me if I misunderstood...

At runtime you can load the desired file from disk with:


However, for this magic to work, you have to add the unit JPEG to the USES clause on top of your Pascal unit. E.g., if it is:

uses  Windows, Messages, { and so on...} ExtCtrls; 

change it to:

uses  Windows, Messages, { and so on...} ExtCtrls, JPEG; 

Without this, you will get an error at the moment that LoadFromFile is executed with a JPG file.

Related articles


Follow Ups