本文介绍了在WPF中绘制到DrawingContext时如何应用阴影效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制为DrawingContext,并且我想对部分图形应用阴影效果.现在,我在DrawingGroup中创建相关部分并应用BitmapEffect,但这没有效果:

I'm drawing into a DrawingContext, and I'd like to apply a drop shadow effect to part of the drawing. At the moment I create the relevant parts in a DrawingGroup and apply a BitmapEffect, but this has no effect:

var layer = new DrawingGroup();
using (var lcontext = layer.Open())
{
    // draw stuff in lcontext
}
layer.BitmapEffect = new DropShadowBitmapEffect { Color = Colors.Black, ShadowDepth = 3, Opacity = 0.5 };
context.DrawDrawing(layer);

这将正确绘制layer内部的所有内容,但没有阴影效果.

This draws everything inside the layer correctly, but without the drop shadow effect.

我在做什么错/我还要如何在DrawingContext中将投影应用于一堆图元?

What am I doing wrong / how else might I apply a drop shadow to a bunch of primitives in a DrawingContext?

推荐答案

BitmapEffect是.NET 3.5之前的旧属性(它们使用了CPU渲染的效果).在4.0中,属性无效.

BitmapEffect is an old property (they used CPU-rendered effects) from pre .NET 3.5. The property has no effect in 4.0.

在4.0中,您应该使用Effect属性,该属性使用Pixel Shaders.

In 4.0 you should use Effect property, which uses Pixel Shaders.

DrawingGroup但是似乎没有效果属性-听起来您可能需要设置对父UI元素的影响.

DrawingGroup however doesn't appear to have an effect property - it sounds like you might need to set the effect on the parent UI element instead.

这篇关于在WPF中绘制到DrawingContext时如何应用阴影效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 14:13