Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 408
  • Last Modified:

Create tImages Dynamicly at runtime.

I need to point (browse) for a folder of images and for example there are 16 jpegs in the folder then i need to populate my Page Control "TabSheet10" with a timage for each jpg (ie. 16 Timages) . I just need a thumbnail view and if i double click on an image it will open the actual picture.jpg with the defalt windows viewer.
This needs to be dynamics so if the are 5 jpeg then 5 Timages will be created on the tabsheet 10.
This information needs to be saved and loaded each time the application is run.
I have no ideal where to start on this and do not want to waste time going in the wronge direction.
I need example code for this.
0
Grant Fullen
Asked:
Grant Fullen
1 Solution
 
ThievingSixCommented:


function CreateTImage(Name: String; Parent: TWinControl; Top, Left, Width, Height: Integer): TImage;
begin
  Result := TImage.Create(Parent);
  Result.Parent := Parent;
  Result.Top := Top;
  Result.Left := Left;
  Result.Width := Width;
  Result.Height := Height;
end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  MyImage : TImage;
begin
  MyImage := CreateTImage('Image1',Form1,0,0,100,100);
  MyImage.Picture.LoadFromFile('C:\Users\Administrator\Desktop\Launcher Creator\Tool Icons\BITMAP\TImage32.bmp');
end;

Open in new window

0
 
ThievingSixCommented:
Make sure you have ExtCtrls in your uses.
0
 
Grant FullenAuthor Commented:
I tried your code and it only loads 1 bmp. I need to load all .jpg in a folder into seperate timages.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Grant FullenAuthor Commented:
I was looking at TJvThumbnail component it supports .jpg this would be better to use than a timage .
0
 
xr1140Commented:
you have to loop the code ThievingSix provided for every image in your folder
0
 
ThievingSixCommented:
And if you wish to use a jpg look here: http://www.thecodecave.com/treating-a-timages-loaded-jpeg-as-a-bitmap-in-delphi/

And as xr1140 says you will need to call CreateTImage for every image in the folder. If you need an example of this look here: http://delphi.about.com/od/vclusing/a/findfile.htm
0
 
ZozzeCommented:
You might wanna use an array of TImages for this purpose

for instance:


const maxpic = 1024;
var
form1: Tform1;
myArr: Array[0..maxpic] of TImage;
 
Procedure loadimages(Pictures:Tstringlist)
var
I:Integer;
Begin
for i = 0 to SizeOf(myArr) do myArr[I].free;// first free any previous instances 
ZeroMemory(@MyArr,SizeOf(MyArr)); // Zero the array;
 
// loop trough the Pictures Tstringlist which will contain filepath of picture
for i = 0 to pictures.count-1 do
begin
//now use the function provided by thievingsix
 MyArr[I] := CreateTImage('Image1',Form1,0,0,100,100); // set the X:Y values after desired position
  MyArr[I].Picture.LoadFromFile(Pictures.strings[0]);
end;
end;
end;
 
 
Hope this was helpfull.

Open in new window

0
 
Grant FullenAuthor Commented:
Have not got to try this stuff yet but will soon.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now