![]() |
TBitmap verkleinern
Hallo Leute
Ich erzeuge ein Hintergrundbild setze ein zweites Bild in die Mitte das klappt soweit. Nun möchte ich das ganze in einer bestimmten größe speichern (100x100) Hat da jemand einen Tipp für Mich wie das am einfachsten geht.
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
var bmpGross, bmpKlein:TBitmap; begin bmpGross:=TBitmap.Create; bmpKlein:=TBitmap.Create; bmpKlein.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Bildklein.bmp'); bmpGross.Width:=600; bmpGross.Height:=600; bmpGross.Canvas.Brush.Color:=clYellow; bmpGross.Canvas.FillRect(Rect(0,0,600,600)); bmpGross.Canvas.Draw(bmpGross.Width div 2 - bmpKlein.Width div 2, bmpGross.Height div 2 - bmpKlein.height div 2, bmpKlein); bmpGross.SaveToFile(ExtractFilePath(ParamStr(0)) + 'BildNeu.bmp'); bmpGross.Free; bmpKlein.Free; end; |
Re: TBitmap verkleinern
Hallo,
mit
Delphi-Quellcode:
kannst du das bild in 100x100 verkleinern
bmpGross.Canvas.StretchDraw(Rect(0,0,100,100), bmpGross);
|
Re: TBitmap verkleinern
Hallo,
oder so:
Delphi-Quellcode:
Das Bild im Image ist das grosse Bild.
var
Bild: TBitmap; begin Bild:= TBitmap.Create; try Bild.Width:= 100; Bild.Height:= 100; SetStretchBltMode(Bild.Canvas.Handle, STRETCH_HALFTONE); SetBrushOrgEx(Bild.Canvas.Handle, 0, 0, nil); StretchBlt(Bild.Canvas.Handle, 0, 0, Bild.Width, Bild.Height, Image1.Picture.Bitmap.Canvas.Handle, 0, 0, Image1.Picture.Bitmap.Width, Image1.Picture.Bitmap.Height, SRCCOPY); finally Bild.SaveToFile('C:\bild.bmp'); end; |
Re: TBitmap verkleinern
Danke für die Antworten, das hatte Ich schon probiert aber dann setz er Mir das 100x100 Bild in die Linke Ecke des großen (600x600).
Delphi-Quellcode:
Irgenwo muss der Fehler stecken nur leider seh Ich ihn nicht. :wink:
procedure TForm1.Button2Click(Sender: TObject);
var bmpGross, bmpKlein:TBitmap; begin bmpGross:=TBitmap.Create; bmpKlein:=TBitmap.Create; bmpKlein.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Bildklein.bmp'); bmpGross.Width:=600; bmpGross.Height:=600; bmpGross.Canvas.Brush.Color:=clYellow; bmpGross.Canvas.FillRect(Rect(0,0,600,600)); bmpGross.Canvas.Draw(bmpGross.Width div 2 - bmpKlein.Width div 2, bmpGross.Height div 2 - bmpKlein.height div 2, bmpKlein); bmpGross.Canvas.StretchDraw(Rect(0,0,100,100), bmpGross); bmpGross.SaveToFile(ExtractFilePath(ParamStr(0)) + 'BildNeu.bmp'); bmpGross.Free; bmpKlein.Free; end; |
Re: TBitmap verkleinern
Wenn Du die Größe des kleinen Bitmaps nicht angibst, kannst Du auch nicht damit rechnen ;)
Delphi-Quellcode:
[edit] Überlesen, dass es aus einer Datei geladen wird, sry [/edit]
bmpGross.Width:=600;
bmpGross.Height:=600; //diese beiden Zeilen fehlen bmpKlein.Width := 100; bmpKlein.Height := 100; |
Re: TBitmap verkleinern
Delphi-Quellcode:
Da du das grosse Bild abspeicherst.
...
bmpGross.Canvas.StretchDraw(Rect(0,0,100,100), bmpGross); bmpGross.Width:= 100; bmpGross.Height:= 100; bmpGross.SaveToFile(ExtractFilePath(ParamStr(0)) + 'BildNeu.bmp'); bmpGross.Free; bmpKlein.Free; end; |
Re: TBitmap verkleinern
Danke euch das wars, da hätt Ich auch drauf kommen können.
Danke |
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:13 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz