Autor Beitrag
pigfacejoe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: Fr 01.02.08 15:09 
Hallo liebe Delphi Community!

Ich bin gerade dabei mir ein Programm zu schreiben, dass Bilder in einem Ordner alle auf die gleiche Breite bringt und die Höhe anpasst. Das klappt auch soweit , allerdings nur mit Bitmaps, denn ich verwende Stretchdraw.
Jetzt meine Frage: Wie kann ich das mit Jpegs machen?

Hier mein Quelltext:
ausblenden 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:
procedure TForm1.BitBtn2Click(Sender: TObject);
var z,br,ho,newho,newbr:integer; quot:real;
begin
button1.Enabled:=false;
if not fileexists(pfad+'\'+'ImageSizer_Output') then  createdir(pfad+'\'+'ImageSizer_Output');
for z:=0 to listbox2.Count-1 do
begin
image1.Picture.LoadFromFile(Listbox2.Items[z]);
showmessage('geladen');
br:=image1.picture.Graphic.Width; //Breite
ho:=image1.picture.Graphic.Height;//Höhe
showmessage('br,ho angepasst');
showmessage(inttostr(br));
quot:= strtofloat(edit3.Text)/ br; //Streckfaktor, in edit3 steht die neue Breite
showmessage('quot angepasst');
showmessage(floattostr(quot));
newho:=   round(quot*ho);   //Neue Höhe wird berechnet
newbr:= strtoint(edit3.Text);//Neue Breite
showmessage(inttostr(newbr));
showmessage(inttostr(newho));
image1.Canvas.StretchDraw(Rect(0,0,newbr,newho),image1.Picture.Graphic);//Anpassen
image1.picture.Graphic.Width:=newbr;//Angepassten abschnitt "ausschneiden"
image1.Picture.Graphic.Height:=newho;
image1.Picture.SaveToFile(pfad+'\'+'ImageSizer_Output\'+listbox1.items[z]);//speichern

showmessage('saved');

end;


Schönen Gruss
PigfaceJoe
pigfacejoe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: Fr 01.02.08 15:34 
Hat sich erledigt, habe mir was anderes einfallen lassen...^^
Hier der Code, mit dem es jetzt klappt:
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:
34:
var z,br,ho,newho,newbr:integer; quot:real;
  J: TJPEGImage;
  B: TBitmap;
begin
button1.Enabled:=false;
if not fileexists(pfad+'\'+'ImageSizer_Output') then  createdir(pfad+'\'+'ImageSizer_Output');
for z:=0 to listbox2.Count-1 do
begin
  J := TJPEGImage.Create;
  B := TBitmap.Create;
J.LoadFromFile(Listbox2.Items[z]);
showmessage('geladen');
br:=J.Width;
ho:=J.Height;
showmessage('br,ho angepasst');
showmessage(inttostr(br));
quot:= strtofloat(edit3.Text)/ br;
showmessage('quot angepasst');
showmessage(floattostr(quot));
newho:=   round(quot*ho);
newbr:= strtoint(edit3.Text);
showmessage(inttostr(newbr));
showmessage(inttostr(newho));
 B.Width := J.Width;
 B.Height := J.Height;
 B.Canvas.Draw (0,0,J);
B.Canvas.StretchDraw(Rect(0,0,newbr,newho),B);
B.Width:=newbr;
B.height:=newho;
B.SaveToFile(pfad+'\'+'ImageSizer_Output\'+listbox1.items[z]);
J.Free;
b.Free;

showmessage('saved');


Gruss
PigfaceJoe