0

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

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

在此处输入图像描述

这是我在 GR32 对象的新图层上绘制它时的结果图像,我之前用以下方法清除了它Clear($00FF0000);

在此处输入图像描述

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

或另一种颜色Clear($000000FF);

在此处输入图像描述

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

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

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($00FF0000);

    {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 一样的清晰结果?

4

2 回答 2

1

据我所知,只要您使用的是cmBlend combine mode ,它就可以按设计工作。cmBlend不考虑背景的 alpha,并且如文档所述,不应用于混合位图:

cmBlend - 使用提供的 alpha 将前景色与背景色快速混合。此方法不适用于处理和保留 Alpha 通道。如果您想直接混合到显示缓冲区,请使用此选项。

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

于 2015-03-04T15:40:24.800 回答
0

我最近遇到了类似的问题

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

TPngImageList 可通过谷歌搜索获得!

于 2015-03-04T09:00:54.770 回答