Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Bildgroesse veraendern (https://www.delphipraxis.net/91524-bildgroesse-veraendern.html)

Lifthrasir 6. Mai 2007 16:38


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:
 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;
....
verzweifel....

könnt ihr mir da mal helfen??

Andreas L. 6. Mai 2007 17:10

Re: Bildgroesse veraendern
 
Delphi-Quellcode:
Image1.loadfromfile('C:\grafik.jpg');
image1.stretch := true;
image1.width := 100;
image1.height := 100;
Aber 1. das Bild würde vermutlich grausam aussehen und 2. kannst du nicht einfach Image1.savetofile benutzen um die Grafik verkleinert zu speichern.

Du wirst dich wohl mit Grafik Bibliotheken wie z. B. Bei Google suchenGraphics32 befassen müssen.

bitsetter 7. Mai 2007 00:01

Re: Bildgroesse veraendern
 
Hi,

für ein Bitmap könnte man es so machen:
Delphi-Quellcode:
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;
In der Delphi Hilfe steht "Hinweis: Stretch hat keine Wirkung, wenn die Eigenschaft Picture ein Bitmap enthält."

SirThornberry 7. Mai 2007 10:23

Re: Bildgroesse veraendern
 
und damit das Bild nach dem Stretchen auch ansehnlich ist sollte man:
Delphi-Quellcode:
SetStretchBltMode(image1.Picture.Bitmap.Canvas.Handle, STRETCH_HALFTONE);
SetBrushOrgEx(image1.Picture.Bitmap.Canvas.Handle, 0, 0, nil);
vor
Delphi-Quellcode:
StretchBlt(image1.Picture.Bitmap.Canvas.Handle, 0, 0, image1.Width,
        image1.Height, Bild.Canvas.Handle, 0, 0, Bild.Width, Bild.Height, srccopy);
aufrufen.

peanut 10. Mai 2007 13:27

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:
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;
Viel Spaß damit und viele Grüße,

peanut.


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:09 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz