ImageEn, unit iexHelperFunctions

IEEstimateImageQuality

IEEstimateImageQuality

Declaration

function IEEstimateImageQuality(const FileName: WideString): Integer; overload;
function IEEstimateImageQuality(Stream: TStream; ImageType: TIOFileType): Integer; overload;

Description

Estimates the quality that was used for saving a JPEG HEIF/HEIC, AVIF or WebP file.
The returned value can then be used for the ImageQuality property (to maintain a similar quality level).
Result will be -1 if an error is encountered, e.g. for an image that is not available or not a supported format.

Note:
◼For JPEG, it uses the (highly accurate) IECalcJpegFileQuality
◼For other formats it performs a calculation based on the bits per pixel. Results will not be particularly accurate, and one of: 30, 50, 65, 75, 85, 90, 95, 100

Examples

ImageEnView1.LoadFromFile( 'C:\input.heic' );
// Do image processing here...
ImageEnView1.IO.Params.ImageQuality := IEEstimateImageQuality('C:\input.heic');
ImageEnView1.IO.SaveToFile('D:\output.heic');


// Save the image as a JPEG at 80% quality, then estimate the quality from the file
ImageEnView1.IO.Params.ImageQuality := 0.80;
ImageEnView1.IO.SaveToStream( ms, ioJPEG );
ms.Position := 0;
q := IEEstimateImageQuality( ms, ioJPEG );
s := Format( 'Estimated quality: %d%%', [ q ]);


ImageTest3.jpg: Estimated quality: 80% (File Size: 23 KB)