1

I have a TBitmap in Delphi with alpha channel. It comes from loading a PNG with a TPNGImage and then extracting the TBitmap.

This works perfectly.

Now, I want to scale this TBitmap, and I found that scaledraw has low quality and does not handle transparency, so I downloaded the Image32 library ( https://github.com/AngusJohnson/Image32 )

The code looks like:

  var inBitmap: TImage32 := TImage32.Create;
  var outBitmap: TBitmap := TBitmap.Create;
  
  try
    inBitmap.CopyFromBitmap(inPict.Bitmap);

    inBitmap.Resampler := rBicubicResampler;
    inBitmap.Resize(scale.Width, scale.Height); // New size
    inBitmap.Crop(newRect); // Take only the required part.

    outBitmap.PixelFormat := pf32bit; // I think it's not required
    inBitmap.CopyToBitmap(outBitmap);
  finally
    FreeAndNil(inBitmap);
    FreeAndNil(outBitmap);
  end;

This seems to work fine on Lazarus FPC, but not on Delphi: the image is scaled, but have weird artifacts:

Before scaled, drawn on top of a flat color:

enter image description here

After scaled, drawn on top of the same flat color:

enter image description here

Note, for drawing, I use the following line:

Canvas.Draw(x, y, outBitmap);

How to properly scale the TBitmap with transparency? (Must be cross-platform with Lazarus/FPC and Linux)

Adrian Maire
  • 14,354
  • 9
  • 45
  • 85

0 Answers0