问题描述
我想使用多重混合模式在现有画布上绘制一些图像。但是,我不知道该怎么做,因为 BlendEffect 类要求我分配背景变量,但这应该是我无法放在那里的画布。
private void OnDrawCanvas(CanvasControl sender,CanvasDrawEventArgs args)
{
var list = new LinkedList<ImageNode>();
mRootNode.GetTraverseList(list,false);
foreach (var item in list)
{
if (!item.treeVisible)
continue;
if (item.mLayerPixels != null)
{
if (item.mLayer.BlendModeKey == BlendModeType.MULTIPLY)
{
var blendEffect = new BlendEffect()
{
//Background = ???,// what to put????
Foreground = item.mLayerPixels,Mode = BlendEffectMode.Multiply
};
args.DrawingSession.DrawImage(blendEffect,item.mLayer.Left,item.mLayer.Top);
}
else
{
args.DrawingSession.DrawImage(item.mLayerPixels,item.mLayer.Top);
}
}
}
}
解决方法
我最终创建了一个离屏 CanvasRenderTarget
来进行混合。完成所有绘图后,我从 CanvasBitmap
创建了一个 CanvasRenderTarget
,它允许我使用 args.DrawingSession.DrawImage();