Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#2

AW: Bitmap manuel als icon speichern

  Alt 19. Jun 2012, 15:20
sowas nützt Dir wahrscheinlich nichts?

Delphi-Quellcode:
function BitmapToIcon(Bitmap: TBitmap;Size:Integer): TIcon;
var

  IconInfo: TIconInfo;
  IconBitmap, MaskBitmap: TBitmap;
  x, y: Integer;
  TransparentColor: TColor;
begin
  Result:= TIcon.Create;
  IconBitmap:= TBitmap.Create;
  MaskBitmap:= TBitmap.Create;
  try
  IconBitmap.Width:= Size;
  IconBitmap.Height:= Size;
  IconBitmap.Canvas.StretchDraw(Rect(0, 0, Size, Size), Bitmap);
  IconBitmap.TransparentColor:= Bitmap.TransparentColor;
  TransparentColor:= IconBitmap.TransparentColor and $FFFFFF;
  
  MaskBitmap.Assign(IconBitmap);
  for y:= 0 to Size - 1 do
    for x:= 0 to Size - 1 do
      if IconBitmap.Canvas.Pixels[x, y] = TransparentColor then
        IconBitmap.Canvas.Pixels[x, y]:= clBlack;
  IconInfo.fIcon:= True;
  IconInfo.hbmMask:= MaskBitmap.MaskHandle;
  IconInfo.hbmColor:= IconBitmap.Handle;
  Result.Handle:= CreateIconIndirect(IconInfo);
  finally
  MaskBitmap.Free;
  IconBitmap.Free;
  end;
end;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)

Geändert von Bummi (19. Jun 2012 um 19:47 Uhr)
  Mit Zitat antworten Zitat