ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 High-quality image format conversion?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

1006 Posts

Posted - Oct 22 2025 :  03:55:27  Show Profile  Reply
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;

xequte

39221 Posts

Posted - Oct 23 2025 :  00:50:27  Show Profile  Reply
Hi Peter

Does the result need to be a TPNGImage, or can it be a TIEBitmap?

As you can assign a TIcon to a TIEBitmap just by using aIEBitmap.Assign( AIcon );



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

1006 Posts

Posted - Oct 24 2025 :  16:45:00  Show Profile  Reply
Hi Nigel,

This should be a generic function that takes any image format as input and returns any image format as output. That would be very useful.
Go to Top of Page

xequte

39221 Posts

Posted - Oct 25 2025 :  20:21:15  Show Profile  Reply
As files, streams or in memory bitmaps? All are possible already.



Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: