Jump to content
A.M. Hoornweg

tImagecollection, how to improve downscaling?

Recommended Posts

Hello all,

 

I have a tImagecollection with square transparent PNG images at 256x256 size which I want to downscale smoothly. The collection's interpolation mode is set to icIMModeHighQualityCubic.

 

I notice that tVirtualImage gives much smoother image quality at 32x32 than tImage if I manually downscale the image using tImageCollection.GetBitmap().   

 

I would very much like to get to the bottom of this.

This is the code I use to manually extract and downscale an image from tImagecollection.

Parameter "Targetimage" is just a TImage on some TPanel on a TForm. Am I doing something wrong?

 

 

procedure LoadImageFromCollection(TargetImage: tImage; ImageName: string; Collection: TImageCollection;
  DesiredHeight: Integer);
var
  tb: tbitmap;
  h,idx: Integer;
begin
  idx := Collection.GetIndexByName(ImageName);
  if idx > -1 then
  begin
    h:=desiredHeight;
    if TargetImage.AlignWithMargins then
      h := h - TargetImage.Margins.Top - TargetImage.Margins.Bottom;
    TargetImage.Height := h;
    TargetImage.width := h;
    TargetImage.Transparent := True;
    tb := Collection.getbitmap(idx, h, h);
    try
      tb.AlphaFormat := afDefined;
      TargetImage.Picture.Bitmap.Assign(tb);
    finally
      tb.free;
    end;
  end;
end;

 

 

Share this post


Link to post
53 minutes ago, A.M. Hoornweg said:

TargetImage.Transparent := True;

Delete this line. It's only (sort of) useful for images without alpha transparency.

  • Like 1

Share this post


Link to post
5 minutes ago, angusj said:

Delete this line. It's only (sort of) useful for images without alpha transparency.

Thank you! Now it works !

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×