1. Computing

How to exchange Bitmap images between two TImageList components

From , former About.com Guide

If you need to send a bitmap image from one TImageList component to another, you can use the next procedure (usage example below):

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure ImageList_MoveBitmap(
   const sourceImageList,
   targetImageList: TImageList;
   const sourcePosition: integer) ;
var
   bitmap : TBitmap;
begin
   bitmap := TBitmap.Create;
   try
     sourceImageList.GetBitmap(sourcePosition,bitmap) ;
     targetImageList.Add(bitmap,nil) ;
sourceImageList.Delete(sourcePosition) ;
   finally
     bitmap.Free;
   end;
end;

//Suppose two TImageList objects present on Form1
//Add Bitmap at position 7 from ImageList1 to the ImageList2
procedure TForm1.BitBtn1Click(Sender: TObject) ;
begin
   ImageList_MoveBitmap(ImageList1, ImageList2, 7) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to clear the graphics in a TImage control
« What does #13#10 stand for, in Delphi code?

©2013 About.com. All rights reserved.