var
NewBitmap: TBitmap;
MS1 : TMemoryStream;
Surf: TBitmapSurface;
JpgQuality : TBitmapCodecSaveParams;
begin
NewBitmap := TBitmap.CreateFromFile('input.bmp');
MS1 := TMemoryStream.Create;
Surf := TBitmapSurface.create;
try
MS1.Position := 0;
Surf.Assign(NewBitmap);
JpgQuality.Quality := 100;
if not TBitmapCodecManager.SaveToStream(MS1, Surf, '.jpg', @JpgQuality) then
raise EBitmapSavingFailed.Create('Error saving Bitmap to jpg');
MS1.SaveToFile('ouput.jpg');
finally
NewBitmap.Free;
MS1.Free;
Surf.Free;
end;
end;