Delphi: GR32 混合 alpha 通道取决于 Clear() 颜色

Delphi: GR32 blending alpha channel is depend on Clear() color

我使用了带有 alpha 通道的图片,并且图像的某些部分不是完全不透明的。当我在 TImgView32 对象上绘制它时,部分会从 Clear() 颜色中获得一点颜色。让我们通过示例图片来展示它:

这是您通常在 Photoshop 中看到的原始图片:

这是我在之前使用 Clear([=14=]FF0000);:

清除的 GR32 对象中的新图层上绘制它时的结果图像

结果像 photohop 一样透明,但红色光晕是问题所在。

或另一种颜色 Clear([=15=]0000FF);:

请注意,如您所知,我使用的颜色是完全透明的。

这是我用来创建上述结果的代码:

begin
  ImageList.Bitmaps.Add;     //ImageList is a TBitmap32List object
  LoadPNGintoBitmap32(ImageList.Bitmap[0], ImgPath+'test.png', DummyBool);

  BL:= TBitmapLayer.Create(ImgView.Layers);
  ImgID:=0;
  ScaleFactor:= 1;
  LayerPos:= Point(100, 100);

  with ImageList.Bitmap[ImgID] do
    ImageRect:= Rect(0, 0, Width, Height);

  {Auxilary variables}
  CanvasWidth:= ImageRect.Right{*2};   //Extending width for two icon.
  CanvasHeight:= ImageRect.Bottom;

  BL.Location:= FloatRect(
    LayerPos.X,
    LayerPos.Y,
    LayerPos.X + CanvasWidth * ScaleFactor,
    LayerPos.Y + CanvasHeight * ScaleFactor
  );

  with BL.Bitmap do
  begin
    {Init}
    SetSize(CanvasWidth, CanvasHeight);
    DrawMode:= dmBlend;
    Clear([=11=]FF0000);

    {Insert image}
    Draw(0, 0, ImageRect, ImageList.Bitmap[ImgID]);
  end;

  if ScaleFactor<>1 then
    TDraftResampler.Create(BL.Bitmap);  //BL.Bitmap, because we used "Draw" method
end;

如何避免这种情况并获得像 photoshop one 一样清晰的结果?

我最近遇到了类似的问题

TImageList 不支持透明,所以当我想在运行时将透明 png 图像加载到控件中时,我不得不使用 TPngImageList。

TPngImageList 可通过 google 搜索获得!

据我所知,它按设计工作,前提是您使用 cmBlend combine mode. cmBlend doesn't take the alpha of the background into account and, as the documentation 状态,不应用于混合位图:

cmBlend - Fast blending of foreground color with the background color using the supplied alpha. This method is not suited for working and preserving alpha-channels. Use this more if you want to blend directly to the display buffer.

当前景和背景 alpha 都很重要时,请改用 cmMerge 组合模式。