![]() |
Bildgroesse veraendern
Hallo Leutz, bevor eine Mahnung kommt, ich hab de Suchfunktion genutzt aber nichts gefunden..
Mein Problem ist folgendes: Ich möchte gerne ein Bild in ein Image laden (ist ja ken problem), doch soll diesse Bild auf eine Größe von 100 mal 100 minnimiert werden, und auch in diesser Größe gespeichert werden.. aber wie so recht?? ich habe x Varianten ausprobiert, aber keine funxt... :(
Delphi-Quellcode:
verzweifel....
begin
Image1.Picture.LoadFromFile(Edit2.Text); // image1.Picture.Bitmap.LoadFromFile(Edit2.Text); // image1.Proportional:=true; // image1.Height:=100; // image1.Width:=100; image1.ClientHeight:=100; image1.ClientWidth:=100; // image1.Picture.Bitmap.Height:=100; // image1.Picture.Bitmap.Width:=100; .... könnt ihr mir da mal helfen?? |
Re: Bildgroesse veraendern
Delphi-Quellcode:
Aber 1. das Bild würde vermutlich grausam aussehen und 2. kannst du nicht einfach Image1.savetofile benutzen um die Grafik verkleinert zu speichern.
Image1.loadfromfile('C:\grafik.jpg');
image1.stretch := true; image1.width := 100; image1.height := 100; Du wirst dich wohl mit Grafik Bibliotheken wie z. B. ![]() |
Re: Bildgroesse veraendern
Hi,
für ein Bitmap könnte man es so machen:
Delphi-Quellcode:
In der Delphi Hilfe steht "Hinweis: Stretch hat keine Wirkung, wenn die Eigenschaft Picture ein Bitmap enthält."
procedure TForm1.Button1Click(Sender: TObject);
var Bild : TBitmap; Pfad : AnsiString; begin Pfad := 'c:\Bild.bmp'; if FileExists(Pfad) then begin Bild := TBitmap.Create; try Bild.LoadFromFile(Pfad); image1.Height := 100; image1.Width := 100; image1.Picture.Bitmap.Height := image1.Height; image1.Picture.Bitmap.Width := image1.Width; StretchBlt(image1.Picture.Bitmap.Canvas.Handle, 0, 0, image1.Width, image1.Height, Bild.Canvas.Handle, 0, 0, Bild.Width, Bild.Height, srccopy); image1.Picture.Bitmap.SaveToFile('C:\BildTest.bmp'); finally Bild.Free; end; end; end; |
Re: Bildgroesse veraendern
und damit das Bild nach dem Stretchen auch ansehnlich ist sollte man:
Delphi-Quellcode:
vor
SetStretchBltMode(image1.Picture.Bitmap.Canvas.Handle, STRETCH_HALFTONE);
SetBrushOrgEx(image1.Picture.Bitmap.Canvas.Handle, 0, 0, nil);
Delphi-Quellcode:
aufrufen.
StretchBlt(image1.Picture.Bitmap.Canvas.Handle, 0, 0, image1.Width,
image1.Height, Bild.Canvas.Handle, 0, 0, Bild.Width, Bild.Height, srccopy); |
Re: Bildgroesse veraendern
Hallo,
ich habe ein ähnliches Problem gehabt und es dank dieses Threads dann gelöst. Vielleicht helfen die folgenden Prozeduren auch anderen weiter:
Delphi-Quellcode:
Viel Spaß damit und viele Grüße,
procedure ResizeTImage(const Image: TImage; Width, Height: Integer);
begin SetStretchBltMode(Image.Picture.Bitmap.Canvas.Handle, STRETCH_HALFTONE); SetBrushOrgEx(Image.Picture.Bitmap.Canvas.Handle, 0, 0, nil); StretchBlt(Image.Picture.Bitmap.Canvas.Handle, 0, 0, Width, Height, Image.Picture.Bitmap.Canvas.Handle, 0, 0, Image.Picture.Bitmap.Width, Image.Picture.Bitmap.Height, SRCCOPY); Image.Picture.Bitmap.Width := Width; Image.Picture.Bitmap.Height := Height; end; procedure ScaledResizeTImage(const Image: TImage; maxWidth, maxHeight: Integer); var r: Double; begin r := Min(maxWidth/Image.Picture.Bitmap.Width, maxHeight/Image.Picture.Bitmap.Height); SetStretchBltMode(Image.Picture.Bitmap.Canvas.Handle, STRETCH_HALFTONE); SetBrushOrgEx(Image.Picture.Bitmap.Canvas.Handle, 0, 0, nil); StretchBlt(Image.Picture.Bitmap.Canvas.Handle, 0, 0, Round(Image.Picture.Bitmap.Width * r), Round(Image.Picture.Bitmap.Height * r), Image.Picture.Bitmap.Canvas.Handle, 0, 0, Image.Picture.Bitmap.Width, Image.Picture.Bitmap.Height, SRCCOPY); Image.Picture.Bitmap.Width := Round(Image.Picture.Bitmap.Width * r); Image.Picture.Bitmap.Height := Round(Image.Picture.Bitmap.Height * r); end; peanut. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:20 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