Autor Beitrag
Dragonclaw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 196

Windows Vista
Delphi 7 Prof.
BeitragVerfasst: Do 16.07.09 14:44 
Hallo.

Ich bin gerade dabei einen Mini-Tool zu schreiben, das mir einen bestimmten Bereich aus einer .jpg heraus kopiert und in einer neuen .jpg abspeichert.

Das .jpg ist im Moment in nem TImange geladen, gibts dafür ne simple Funktion oder ist das schwieriger als ich mir das vorstelle?

Vielen Dank im Vorraus.
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Do 16.07.09 14:57 
Mit der Funktion CopyRect kannst du bereiche aus einem Bild kopieren. näheres einfach in der Hilfe nachschauen. ;)

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Dragonclaw Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 196

Windows Vista
Delphi 7 Prof.
BeitragVerfasst: Do 16.07.09 15:49 
Okay nach nem bisschen rumspiele und noch ein paar Probleme, klappst jetzt.

Das ganze wird in 3 schritten gemacht


1) .jpg --> .bmp
2) .bmp croppen
3) .bmp --> .jpg

Quick&Dirty sieht das dann so aus

ausblenden volle Höhe 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:
30:
31:
32:
33:
var dest,source: Trect;
  jpeg: TJPEGImage;
  bmp:  TBitmap;
begin
 
//SCHRITT 1
  jpeg := TJPEGImage.Create;
  jpeg.CompressionQuality := 100; {Default Value}
  jpeg.LoadFromFile(Listbox1.Items[Listbox1.ItemIndex]);
  bmp := TBitmap.Create;
  bmp.Assign(jpeg);

//SCHRITT 2
  dest.TopLeft.X := 0;
  dest.TopLeft.Y := 0;
  dest.BottomRight.x := 419;
  dest.BottomRight.Y := 306;
  source.TopLeft.X := 31;
  source.TopLeft.Y := 71;
  source.BottomRight.x := 450;
  source.BottomRight.Y := 377;
  image2.Picture.Bitmap :=bmp; 
  image1.Canvas.CopyRect(dest,Image2.canvas,source);
  image1.Canvas.Refresh;

//SCHRITT 3
  jpeg := TJPEGImage.Create;
  jpeg.CompressionQuality := 100; {Default Value}
  jpeg.Assign(image1.Picture.Graphic);
  jpeg.SaveToFile(Listbox1.Items[Listbox1.ItemIndex]);
  bmp.Free;
  jpeg.Free;
end;



Das ganze muss doch irgendwie kürzer gehen oder?
jfheins
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 918
Erhaltene Danke: 158

Win 10
VS 2013, VS2015
BeitragVerfasst: Do 16.07.09 17:56 
1. Du brauchst das TImage gar nicht, du kannst alles Mit dem Bitmap machen

2. Es sollte ein Funktion Rect() geben, der du 4 Werte übergibst und die dir dann ein TRect zurückliefert

3. Die freigewordenen zeilen kanst du dann mit try-finally auffüllen :P