Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#2

Re: Bitmap zu Icon ohne Farbe Verlust ?

  Alt 23. Aug 2008, 13:20
Hallo,

So wird die Qualität besser:

Delphi-Quellcode:
uses
  IconsToFile; {Siehe Anhang icon2file.zip}

function Bmp2Ico(Bitmap: TBitmap; IcoFileName: TFilename): Boolean;
var
  Icon: TIcon;
  ImageList: TImageList;
begin
  Result := False;
  ImageList := TImageList.CreateSize(Bitmap.Width, Bitmap.Height);
  try
    ImageList.AllocBy := 1;
    ImageList.AddMasked(Bitmap, Bitmap.TransparentColor);
    Icon := TIcon.Create;
    try
      ImageList.GetIcon(0, Icon);
      Result := hicontofile(IcoFileName, Icon.Handle, BitC24) <> -1;
     // Icon.SaveToFile(IcoFileName);
    finally
      Icon.Free;
    end;
  finally
    ImageList.Free;
  end;
end;
// Beispiel:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
  Bmp2Ico(Image1.Picture.Bitmap, 'c:\Output.ico');
end;
Angehängte Dateien
Dateityp: zip icon2file_133.zip (19,7 KB, 52x aufgerufen)
Thomas
  Mit Zitat antworten Zitat