Mega Code Archive

 
Categories / Delphi / Graphic
 

Convert a bitmap to an icon

// Add these units to your uses-section: // Folgende units hinzufügen: uses Graphics, Controls { Creates an TIcon object from a TBitmap. Handy for dynamically updating your application's icon. I use it often to update my application's tray icon. Erzeugt ein TIcon aus einem TBitmap Objekt. Es ist nützlich, um das Icon der Applikation dynamisch zu verändern. } function CreateIconFromBitmap(Bitmap: TBitmap; TransparentColor: TColor): TIcon; begin with TImageList.CreateSize(Bitmap.Width, Bitmap.Height) do begin try AllocBy := 1; AddMasked(Bitmap, TransparentColor); Result := TIcon.Create; try GetIcon(0, Result); except Result.Free; raise; end; finally Free; end; end; end;