gpt4 book ai didi

delphi - 如何在 VirtualTreeView 中将单元格与背景图像混合颜色?

转载 作者:行者123 更新时间:2023-12-03 14:56:06 32 4
gpt4 key购买 nike

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

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

知道如何做到这一点吗?

最佳答案

只是尝试猜测这是否是您正在寻找的内容:

更新:
添加了非 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;

上面代码的预览:

enter image description here

关于delphi - 如何在 VirtualTreeView 中将单元格与背景图像混合颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10537016/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com