Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TJpegImage and compression 3

Status
Not open for further replies.

towerbase

Programmer
Jul 31, 2002
1,053
GB
I have never been able to get Delphi to compress a jpeg image. I set CompressionQuality to any value and then call Compress but the file is always saved with a length of zero bytes. Can someone tell me what I'm doing wrong? (It fails, for me, with Delphi 5 and Delphi 7).
Code:
uses jpeg;

procedure TForm1.GoClick(Sender: TObject);
const
  path = 'c:\';
var
  jpeg: TJpegImage;
begin
  jpeg := TJpegImage.Create;
  try
    jpeg.LoadFromFile( path + 'Old.jpg');
    jpeg.CompressionQuality := 50;
    jpeg.Compress;
    jpeg.SaveToFile ( path + 'New.jpg' );
  finally
    jpeg.Free;
  end;
end;

Andrew
 
//--------------------------------------------
uses jpeg;

procedure TForm1.GoClick(Sender: TObject);
const
path = 'c:\';
var
jpeg: TJpegImage;
bmp: TBitmap;
begin
jpeg := TJpegImage.Create;
bmp := TBitmap.Create;
try
jpeg.LoadFromFile( path + 'Old.jpg');
bmp.Assign(jpeg);
jpeg.Assign(bmp);
jpeg.CompressionQuality := 50;
jpeg.Compress;
jpeg.SaveToFile ( path + 'New.jpg' );
finally
bmp.Free;
jpeg.Free;

end;
end;
 
Now why didn't I try that?

Many thanks, halfyawn. Your code works. A star for you.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top