I try to load an image in imgQInput (which is a TImage), assign it to a TJpegImage, compress it (compression factor 5) and show it in imgQOutput (another TImage). But it doesn’t work. The image in imgQOutput is the same as the original. It should look VERY pixelated because of the compression factor! The compression works however, because when I save the JPEG to disk it is really small.
JPG:= TJPEGImage.Create;
TRY
JPG.CompressionQuality:= trkQuality.Position;
JPG.Assign(imgQInput.Picture.Graphic);
CompressJpeg(JPG);
imgQOutput.Picture.Assign(JPG); <--------- something wrong here. the shown image is not the compressed image but the original one
FINALLY
FreeAndNil(JPG);
END;
function CompressJpeg(OutJPG: TJPEGImage): Integer;
VAR tmpQStream: TMemoryStream;
begin
tmpQStream:= TMemoryStream.Create;
TRY
OutJPG.Compress;
OutJPG.SaveToStream(tmpQStream);
OutJPG.SaveToFile('c:\CompTest.jpg'); <--------------- this works
Result:= tmpQStream.Size;
FINALLY
FreeAndNil(tmpQStream);
END;
end;
You did not used the compressed JPG at all.
Change
CompressJpegas followings: