-->

如何颜色相混合细胞与VirtualTreeView背景图像?(How to color blend

2019-06-24 07:57发布

我使用VT.Background显示在VT背景图像有几列。
但我不能找到一种方法,因为他们隐藏背景图像用于细胞不同的颜色。

我曾尝试使用OnBeforeItemErase但如果我用EraseAction := eaColor单元上的背景位图区域也被画,如果我用eaDefault没有施加颜色。

任何想法,这可怎么办呢?

Answer 1:

只是试图想如果这是你在找什么:

更新:
增加了一个颜色混合功能非CPU MMX机器。

procedure ColorBlend(const ACanvas: HDC; const ARect: TRect;
  const ABlendColor: TColor; const ABlendValue: Integer);
var
  DC: HDC;
  Brush: HBRUSH;
  Bitmap: HBITMAP;
  BlendFunction: TBlendFunction;
begin
  DC := CreateCompatibleDC(ACanvas);
  Bitmap := CreateCompatibleBitmap(ACanvas, ARect.Right - ARect.Left,
    ARect.Bottom - ARect.Top);
  Brush := CreateSolidBrush(ColorToRGB(ABlendColor));
  try
    SelectObject(DC, Bitmap);
    Windows.FillRect(DC, Rect(0, 0, ARect.Right - ARect.Left,
      ARect.Bottom - ARect.Top), Brush);
    BlendFunction.BlendOp := AC_SRC_OVER;
    BlendFunction.BlendFlags := 0;
    BlendFunction.AlphaFormat := 0;
    BlendFunction.SourceConstantAlpha := ABlendValue;
    Windows.AlphaBlend(ACanvas, ARect.Left, ARect.Top,
      ARect.Right - ARect.Left, ARect.Bottom - ARect.Top, DC, 0, 0,
      ARect.Right - ARect.Left, ARect.Bottom - ARect.Top, BlendFunction);
  finally
    DeleteObject(Brush);
    DeleteObject(Bitmap);
    DeleteDC(DC);
  end;
end;

procedure TForm1.VirtualStringTree1BeforeCellPaint(Sender: TBaseVirtualTree;
  TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
  BlendColor: TColor;
  BlendValue: Integer;
begin
  if CellPaintMode = cpmPaint then
  begin
    case Column of
      0: BlendColor := $000080FF;
      1: BlendColor := $0046C2FF;
      2: BlendColor := $0046F5FF;
    end;
    BlendValue := 145;
    if not VirtualTrees.MMXAvailable then
      ColorBlend(TargetCanvas.Handle, CellRect, BlendColor, BlendValue)
    else
      VirtualTrees.Utils.AlphaBlend(0, TargetCanvas.Handle, CellRect, Point(0, 0),
        bmConstantAlphaAndColor, BlendValue, ColorToRGB(BlendColor));
  end;
end;

上面的代码的预览:



文章来源: How to color blend cells with a background image in VirtualTreeView?