【问题标题】:How to color blend cells with a background image in VirtualTreeView?如何在 VirtualTreeView 中为混合单元格与背景图像着色?
【发布时间】:2012-05-10 15:11:24
【问题描述】:

我正在使用 VT.Background 在 VT 中显示具有几列的背景图像。
但我找不到为单元格使用不同颜色的方法,因为它们隐藏了背景图像。

我尝试使用OnBeforeItemErase,但如果我使用EraseAction := eaColor,单元格上的背景位图区域也会被绘制,如果我使用eaDefault,则不会应用颜色。

知道如何做到这一点吗?

【问题讨论】:

  • 您希望单元格的哪个部分包含不同的颜色?你的意思是 text 颜色?你的意思是背景,但只是文本占据的部分?请编辑问题以更具体。
  • 您的意思是在某些单元格中使用不同的背景颜色,但仍与背景图像混合?

标签: delphi delphi-7 virtualtreeview tvirtualstringtree


【解决方案1】:

只是尝试猜测这是否是您要查找的内容:

更新:
为非 MMX CPU 机器添加了颜色混合功能。

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;

以上代码预览:

【讨论】:

  • @Leonardo,谢谢!我刚刚为非 MMX CPU 机器添加了一个颜色混合功能(希望这是正确和最简单的方法),但这仍然只是猜测这里问的是什么 ;-)
猜你喜欢
  • 2012-07-22
  • 2014-01-14
  • 2020-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-20
  • 2019-05-19
  • 1970-01-01
相关资源
最近更新 更多