hyperreal
asked on
How to I copy an image from a TImageList to a TImage in Delphi?
Hi all, I hope you can help me out here!
I have a form in Delphi 6 which consists of a TImage and TImageList. My TImageList consists of various icons, and I'd like to put one of them in the TImage so that it is displayed on the form - for example the first image in the list (0).
How to I copy an image from a TImageList to a TImage?
I want to then save the TImage as a PNG image file, that I can do using some demo code I've obtained elsewhere, however if anyone can show me a better of doing this, I'd be most grateful! Cheers.
Matt.
I have a form in Delphi 6 which consists of a TImage and TImageList. My TImageList consists of various icons, and I'd like to put one of them in the TImage so that it is displayed on the form - for example the first image in the list (0).
How to I copy an image from a TImageList to a TImage?
I want to then save the TImage as a PNG image file, that I can do using some demo code I've obtained elsewhere, however if anyone can show me a better of doing this, I'd be most grateful! Cheers.
Matt.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Doh! You just change the Height and Width in the ImageList.
Any ideas how I can export this image as a PNG or GIF file from the TImage? I've tried using the ImageFileLib for Delphi code as developed by Michael Vinther, but I cant get it to work :(
This is my code so far :-
procedure TForm1.Button3Click(Sender : TObject);
begin
ImageList1.GetBitmap(0,Ima ge1.Pictur e.Bitmap);
Image1.Repaint(); // forces a repaint
Image1.Picture.SaveToFile( 'c:\test.b mp');
with TLinearBitmap.Create do
try
GetFromTBitmap(Image1.Pict ure.Bitmap );
SaveToFile('C:\test.png');
finally
Free;
end;
end;
Any ideas how I can export this image as a PNG or GIF file from the TImage? I've tried using the ImageFileLib for Delphi code as developed by Michael Vinther, but I cant get it to work :(
This is my code so far :-
procedure TForm1.Button3Click(Sender
begin
ImageList1.GetBitmap(0,Ima
Image1.Repaint(); // forces a repaint
Image1.Picture.SaveToFile(
with TLinearBitmap.Create do
try
GetFromTBitmap(Image1.Pict
SaveToFile('C:\test.png');
finally
Free;
end;
end;
ASKER
Doh! You just change the Height and Width in the ImageList.
Any ideas how I can export this image as a PNG or GIF file from the TImage? I've tried using the ImageFileLib for Delphi code as developed by Michael Vinther, but I cant get it to work :(
This is my code so far :-
procedure TForm1.Button3Click(Sender : TObject);
begin
ImageList1.GetBitmap(0,Ima ge1.Pictur e.Bitmap);
Image1.Repaint(); // forces a repaint
Image1.Picture.SaveToFile( 'c:\test.b mp');
with TLinearBitmap.Create do
try
GetFromTBitmap(Image1.Pict ure.Bitmap );
SaveToFile('C:\test.png');
finally
Free;
end;
end;
Any ideas how I can export this image as a PNG or GIF file from the TImage? I've tried using the ImageFileLib for Delphi code as developed by Michael Vinther, but I cant get it to work :(
This is my code so far :-
procedure TForm1.Button3Click(Sender
begin
ImageList1.GetBitmap(0,Ima
Image1.Repaint(); // forces a repaint
Image1.Picture.SaveToFile(
with TLinearBitmap.Create do
try
GetFromTBitmap(Image1.Pict
SaveToFile('C:\test.png');
finally
Free;
end;
end;
ASKER