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
 IEResampleImageFile issue
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

papa.john

9 Posts

Posted - Aug 19 2023 :  03:26:42  Show Profile  Reply
Hello! I want to create 16x16 icon from PNG image (with transparency) using this function:

IEResampleImageFile('1.png', '1.ico', 0, 16, 16);


The problem is that as a result all transparent areas are replaced with black color. How to make result ico with transparent areas, or at least replace them with white color instead of black?

xequte

38613 Posts

Posted - Aug 19 2023 :  23:32:01  Show Profile  Reply
Hi

Please use this updated version of IEResampleImageFile:

function IEResampleImageFile(const sInFilename, sOutFilename: string;
                             JpegQuality: Integer;
                             MaxX, MaxY: Integer;
                             StretchSmall: Boolean = False;
                             QualityFilter: TResampleFilter = rfLanczos3;
                             AutoAdjustOrientation: Boolean = False;
                             bStripMetaData: Boolean = False
                             ): Boolean;
var
  ABitmap: TIEBitmap;
  io: TImageEnIO;
  ASize: TPoint;
begin
  result := true;
  ShowTempHourglass();
  try
    ABitmap := TIEBitmap.create();
    io := TImageEnIO.CreateFromBitmap(ABitmap);                               
    try
      io.Params.GetMetaData := not bStripMetaData;

      // Load full size for best quality (and avoid size discrepency if we are auto-rotating)
      if io.LoadFromFileEx(sInFilename, -1, -1, AutoAdjustOrientation) = False then
        raise EIEException.create( IEExceptionMsg( ieexReadError ));

      if StretchSmall or (ABitmap.width > MaxX) or (ABitmap.height > MaxY) then
      begin
        // Resize the image
        ASize := GetImageSizeWithinArea(ABitmap.Width, ABitmap.Height, MaxX, MaxY);
        ABitmap.Resample(ASize.X, ASize.Y, QualityFilter);
      end;

      if bStripMetaData then
        io.Params.ResetInfo();

      if not io.SaveToFileEx(sOutFilename, JpegQuality) then
        raise EIEException.create( IEExceptionMsg( ieexWriteError ));

    finally
      io.Free;
      ABitmap.Free;
    end;
  except
    result := false;
  end;
end;


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