在 Delphi 中使用 Alpha 通道调整 TBitmap 的大小

问题描述 投票:0回答:1

我在 Delphi 中有一个带有 alpha 通道的

TBitmap
。它来自于用 TPNGImage 加载 PNG,然后提取 TBitmap。

这非常有效。

现在,我想要缩放这个TBitmap,我发现

scaledraw
的质量很低并且不处理透明度,所以我下载了Image32库(https://github.com/AngusJohnson/Image32

代码如下:

  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;

这似乎在 Lazarus FPC 上运行良好,但在 Delphi 上则不然:图像已缩放,但有奇怪的伪像:

缩放之前,绘制在平面颜色之上:

缩放后,绘制在相同的平面颜色之上:

注意,对于绘图,我使用以下行:

Canvas.Draw(x, y, outBitmap);

如何正确缩放TBitmap并使其透明?(必须与Lazarus/FPC和Linux跨平台)

delphi transparency image-scaling image32
1个回答
0
投票

我确信这个问题不在 Image32 库中。
请参阅此处的讨论:
https://github.com/AngusJohnson/Image32/issues/30

© www.soinside.com 2019 - 2024. All rights reserved.