Does the ImageEn library have a method for high-quality image format conversion, preserving transparency?
I tried this one for converting from Icon to PNG, but it is not optimal:
function IconToPng(AIcon: Vcl.Graphics.TIcon; ASize: Integer): Vcl.Imaging.pngimage.TPngImage;
var
IEBitmap: TIEBitmap;
ImageEnIO: TImageEnIO;
IconStream, PngStream: TMemoryStream;
begin
Result := TPngImage.Create;
try
IEBitmap := TIEBitmap.Create;
try
ImageEnIO := TImageEnIO.Create(nil);
try
ImageEnIO.AttachedIEBitmap := IEBitmap;
IconStream := TMemoryStream.Create;
try
// Save icon to memory stream
AIcon.SaveToStream(IconStream);
IconStream.Position := 0;
// Load icon with ImageEn (preserves alpha)
ImageEnIO.LoadFromStreamICO(IconStream);
// Try Mitchell filter for better quality (good for downsampling)
// Or try rfBSpline as alternative
IEBitmap.Resample(ASize, ASize, rfMitchell);
// Optionally apply slight sharpening after resample
// IEBitmap.Filter_Sharpen(1);
// Write directly to PNG stream, then load into TPngImage
PngStream := TMemoryStream.Create;
try
ImageEnIO.SaveToStreamPNG(PngStream);
PngStream.Position := 0;
Result.LoadFromStream(PngStream);
finally
PngStream.Free;
end;
finally
IconStream.Free;
end;
finally
ImageEnIO.Free;
end;
finally
IEBitmap.Free;
end;
except
Result.Free;
raise;
end;
end;