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.
hyperrealAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mocartsCommented:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ImageList1.GetBitmap(0, Image1.Picture.Bitmap);
end;

wbr, mo.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hyperrealAuthor Commented:
Cheers mocarts, this worked however only gives me the 16x16pixel icon image. How do I get the 32x32 image?
0
hyperrealAuthor Commented:
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,Image1.Picture.Bitmap);
  Image1.Repaint(); // forces a repaint
  Image1.Picture.SaveToFile('c:\test.bmp');

  with TLinearBitmap.Create do
    try
      GetFromTBitmap(Image1.Picture.Bitmap);
      SaveToFile('C:\test.png');
    finally
      Free;
    end;

end;
0
hyperrealAuthor Commented:
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,Image1.Picture.Bitmap);
  Image1.Repaint(); // forces a repaint
  Image1.Picture.SaveToFile('c:\test.bmp');

  with TLinearBitmap.Create do
    try
      GetFromTBitmap(Image1.Picture.Bitmap);
      SaveToFile('C:\test.png');
    finally
      Free;
    end;

end;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.