Link to home
Start Free TrialLog in
Avatar of hyperreal
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.
ASKER CERTIFIED SOLUTION
Avatar of mocarts
mocarts

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hyperreal
hyperreal

ASKER

Cheers mocarts, this worked however only gives me the 16x16pixel icon image. How do I get the 32x32 image?
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;
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;