Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-16
4
Medium Priority
?
903 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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

580 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