如何使用VirtualTreeView中的背景图像混合单元格? [英] How to color blend cells with a background image in VirtualTreeView?

查看:259
本文介绍了如何使用VirtualTreeView中的背景图像混合单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VT.Background在VT中显示一些背景图像,其中包含几列。

但是,由于隐藏了背景图像,我找不到使用不同颜色的单元格的方法。

I'm using VT.Background to display a background image in VT with a few columns.
But I can't find a way to use different colors for cells because they hide the background image.

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

I have tried to use OnBeforeItemErase but if I useEraseAction := eaColor the background bitmap area on the cell is also being painted, if I use eaDefault the color is not being applied.

任何想法如何才能完成?

Any idea how this can be done?

推荐答案

只是试图猜测这是你正在看的for:

Just an attempt to guess if that's what you are looking for:

更新:

为非MMX CPU机器添加了色彩混合功能

Update:
Added a color blending function for non MMX CPU machines.

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;

上面的代码预览:

这篇关于如何使用VirtualTreeView中的背景图像混合单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆