Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Umwandlung TIcon -> TBitmap (https://www.delphipraxis.net/301-umwandlung-ticon-tbitmap.html)

thomasdrewermann 30. Jun 2002 09:51


Umwandlung TIcon -> TBitmap
 
Hi,
hat jemand eine Idee wie man ein TIcon mit 32*32 Pixel in ein TBitmap mit 32*32 Pixel konvertieren kann?

MFG
Thomas

Daniel 30. Jun 2002 10:23

Hi,

ich habe zuhause eine Funktion, die ich Dir am späten Nachmittag zur Verfügung stellen kann. Sie basiert darauf, dass ein TBitmap eine Canvas bereits stellt, auf die man das TIcon zeichnen kann. Vorher noch mit TBitmap.Width / TBitmap.Height die Größe angepasst, die Farbtiefe im Zweifelsfall lieber etwas zu hoch gewählt und schon geht's los :-)


Grüße,
Daniel

sakura 30. Jun 2002 10:35

That's it.

Code:
[b]var[/b]
  Bitmap: TBitmap;
  Icon: TIcon;
[b]begin[/b]
  Icon := TIcon.Create;
  Bitmap := TBitmap;
  [b]try[/b]
    Icon.Handle := ICONHANDLE von Irgendwo;
    Bitmap.Width := Icon.Width;
    Bitmap.Height := Icon.Height;
    Bitmap.Canvas.Draw(0, 0, Icon);
    .....
  [b]finally[/b]
    Bitmap.Free;
    Icon.Free;
  [b]end[/b];
[b]end[/b];
:cat:

thomasdrewermann 30. Jun 2002 12:37

Jo danke :D

thomasdrewermann 30. Jun 2002 12:41

Hast du auch ne Idee für den umgekehrten Weg?

Luckie 2. Aug 2003 20:58

Re: Umwandlung TIcon -> TBitmap
 
Genau umgekehrt:
Delphi-Quellcode:
// ein Bitmap wird zu einem Iconprocedure
TForm1.Button1Click(Sender: TObject);
var bm1,bm2:TBitmap;
  ic:TIcon;Iinfo:TIconInfo;
begin
  ic:=TIcon.Create;
  bm1:=TBitmap.create;
  try
    bm1.loadfromfile('d:\bilder\vogel.bmp');
    bm2:=TBitmap.create;
    bm2.width:=ic.width;
    bm2.height:=ic.height;
    bm2.canvas.stretchdraw(rect(0,0,bm2.width,bm2.height),bm1);
    bm1.assign(bm2);
    bm2.monochrome:=true;
    Iinfo.fIcon:=true;
    Iinfo.xHotspot:=0;
    Iinfo.yHotspot:=0;
    Iinfo.hbmMask:=bm2.Handle;
    Iinfo.hbmColor:=bm1.Handle;
    ic.Handle:=CreateIconIndirect(Iinfo);
    ic.savetofile('c:\test.ico');
  finally
    bm2.free;
    bm1.free;
  ic.free;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:06 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz