Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi TBitmap verkleinern (https://www.delphipraxis.net/103349-tbitmap-verkleinern.html)

Blackheart 14. Nov 2007 17:00


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;

kevSTAR 14. Nov 2007 17:26

Re: TBitmap verkleinern
 
Hallo,

mit

Delphi-Quellcode:
bmpGross.Canvas.StretchDraw(Rect(0,0,100,100), bmpGross);
kannst du das bild in 100x100 verkleinern

bitsetter 14. Nov 2007 17:29

Re: TBitmap verkleinern
 
Hallo,

oder so:
Delphi-Quellcode:
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;
Das Bild im Image ist das grosse Bild.

Blackheart 14. Nov 2007 17:33

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:
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;
Irgenwo muss der Fehler stecken nur leider seh Ich ihn nicht. :wink:

DeddyH 14. Nov 2007 17:35

Re: TBitmap verkleinern
 
Wenn Du die Größe des kleinen Bitmaps nicht angibst, kannst Du auch nicht damit rechnen ;)
Delphi-Quellcode:
  bmpGross.Width:=600;
  bmpGross.Height:=600;
  //diese beiden Zeilen fehlen
  bmpKlein.Width := 100;
  bmpKlein.Height := 100;
[edit] Überlesen, dass es aus einer Datei geladen wird, sry [/edit]

bitsetter 14. Nov 2007 17:52

Re: TBitmap verkleinern
 
Delphi-Quellcode:
...
  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;
Da du das grosse Bild abspeicherst.

Blackheart 14. Nov 2007 17:57

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