Hey leute
hab ein prob,ich will ein bitmap oder das image in ein icon umwandeln doch leider klappt das nicht ganz so
ursprungscode:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
| procedure TForm1.Button1Click(Sender: TObject); var s : string; Icon: TIcon; begin OpenDialog1.DefaultExt := '.ICO'; OpenDialog1.Filter := 'icons (*.ico)|*.ICO'; OpenDialog1.Options := [ofOverwritePrompt, ofFileMustExist, ofHideReadOnly ]; if OpenDialog1.Execute then begin Icon := TIcon.Create; try Icon.Loadfromfile(OpenDialog1.FileName); s:= ChangeFileExt(OpenDialog1.FileName,'.BMP'); Image1.Width := Icon.Width; Image1.Height := Icon.Height; Image1.Canvas.Draw(112,0,Icon); Image1.Picture.SaveToFile(s); ShowMessage(OpenDialog1.FileName + ' Saved to ' + s); finally Icon.Free; end; end; |
ich hab dann folgendes geändert oder neugeschrieben
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29:
| begin OpenDialog1.DefaultExt := '.BMP'; OpenDialog1.Filter := 'Bitmap (*.bmp)|*.BMP'; OpenDialog1.Options := [ofOverwritePrompt, ofFileMustExist, ofHideReadOnly ]; if openDialog1.execute then Bitmap:=Tbitmap.Create; begin Image1.Picture.LoadFromFile(openDialog1.Filename); end; Bmp := TBitmap.Create; Icon := TIcon.Create; try Bmp.Assign(Image1.Picture); ImageList := TImageList.CreateSize(Bmp.Width, Bmp.Height); try ImageList.AddMasked(Bmp, Bmp.TransparentColor); ImageList.GetIcon(0, Icon); s:= ChangeFileExt(OpenDialog1.FileName,'.ICO'); Icon.SaveToFile(s); finally ImageList.Free; end; finally Bmp.Free; Icon.Free; end; ShowMessage(OpenDialog1.FileName + ' Saved to ' + s); end; |
soweit so gut aber immer wenn ich konveriere kommt ein hässliches icon raus was warscheinlich an dem transparentcolor liegt es,gibt es da noch andere color eigenschaften?oder was muss ich machen das der es schön,richtig konvertiert?