Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Form-Icon wird invers angezeigt (https://www.delphipraxis.net/164604-form-icon-wird-invers-angezeigt.html)

marcibaer 21. Nov 2011 15:34

Form-Icon wird invers angezeigt
 
Hallo zusammen!

Ich versuche, die Bitmaps, die auf meinen ToolButtons angezeigt werden, auch als Icon der zugehörigen Forms anzeigen zu lassen.

Im Netz hab ich dazu folgendes gefunden:
Delphi-Quellcode:
function CreateIconFromBitmap(Bitmap:TBitmap):TIcon;
begin
  with TImageList.CreateSize(Bitmap.Width, Bitmap.Height) do
  begin
    try
      AllocBy := 1;
     {$IFDEF VER90}
      with Bmp do
        AddMasked(Bitmap, Canvas.Pixels[Width-1, Height-1]);
     {$ELSE}
      AddMasked(Bitmap, Bitmap.TransparentColor);
     {$ENDIF}
      Result := TIcon.Create;
      try
        GetIcon(0, Result);
      except
        Result.Free;
        raise;
      end;
    finally
      Free;
    end;
  end;
end;

function GetIcon(Index:Word):TIcon;
var
  Image: TBitmap;
begin
  Image := TBitmap.Create;
  ImageList1.GetBitmap(Index,Image);
  Result := CreateIconFromBitmap(Image);
  Image.Free;
end;
Ich setze das Icon dann im FormCreate des Forms z.B. mit
Delphi-Quellcode:
  Ic := GetIcon(18);
  Icon.Handle := IC.Handle;
  IC.Free;
Angezeigt wird es auch - allerdings invers und farblos!

Wie kann ich das korrigieren!?

Danke für Eure Hilfe ...

Bummi 21. Nov 2011 15:58

AW: Form-Icon wird invers angezeigt
 
ich könnte folgendes anbieten

Delphi-Quellcode:
procedure Bitmap2Icon(BMP: TBitmap; Ico: TIcon);
var
    IconInfo : TIconInfo;
begin
        BMP.PixelFormat  := pf24bit;
        IconInfo.fIcon   := true;
        IconInfo.xHotspot := 0;
        IconInfo.yHotspot := 0;
        IconInfo.hbmMask := BMP.Handle;
        IconInfo.hbmColor := BMP.Handle;
        Ico.Handle       := CreateIconIndirect(IconInfo);
end;



procedure TForm2.Button1Click(Sender: TObject);
begin
  Bitmap2Icon(Image1.Picture.Bitmap,Icon);
end;

DeddyH 21. Nov 2011 16:30

AW: Form-Icon wird invers angezeigt
 
Würde das hier nicht auch genügen?
Delphi-Quellcode:
procedure TForm1.IconFromList(Index: integer);
begin
  ImageList1.GetIcon(Index, self.Icon);
end;

marcibaer 21. Nov 2011 16:35

AW: Form-Icon wird invers angezeigt
 
@Bummi: Icon ist nun bunt, dafür ist der Hintergrund orange!

@DeddyH: Top - funktioniert einwandfrei. Manchmal ist es doch ganz einfach!

Danke, Euch beiden ...


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:20 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