?
Solved

How to I copy an image from a TImageList to a TImage in Delphi?

Posted on 2003-03-16
4
Medium Priority
?
876 Views
Last Modified: 2007-12-19
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.
0
Comment
Question by:hyperreal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 9

Accepted Solution

by:
mocarts earned 150 total points
ID: 8146818
procedure TForm1.Button1Click(Sender: TObject);
begin
  ImageList1.GetBitmap(0, Image1.Picture.Bitmap);
end;

wbr, mo.
0
 

Author Comment

by:hyperreal
ID: 8147354
Cheers mocarts, this worked however only gives me the 16x16pixel icon image. How do I get the 32x32 image?
0
 

Author Comment

by:hyperreal
ID: 8147370
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
 

Author Comment

by:hyperreal
ID: 8147489
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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question