移动时,VisualBrush for Image的WPF问题

时间:2012-09-25 15:05:20

标签: wpf image visualbrush

我有Image,当我将对象从一个点移动到另一个点时,我已经为图像创建了可视化画笔。但是我没有在视觉刷上看到图像。如果你看到我的矩形,它会假设显示图像。

见图片:http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e8833983-3d73-45e1-8af1-3bc27846441d

这是代码:

internal static VisualBrush GetVisualBrushByObject(LabelObject obj, Rect objectRect, int quality, FlowDirection flowdirection)
    {
        DrawingVisual drawingVisual = new DrawingVisual();
        DrawingContext drawingContext = drawingVisual.RenderOpen();
        Rect objectbounds = new Rect(0, 0, objectRect.Width, objectRect.Height);
        if (obj is TextObject)
        {
            TextObject txtObj = obj.Clone() as TextObject;
            DymoTextBlock txtBlock = txtObj.DymoTextBlock as DymoTextBlock;
            objectbounds = new Rect(txtBlock.GetNaturalSize(txtBlock.GetFormattedText(flowdirection)));
        }
        if (obj is ImageObject)
        {
            drawingContext.DrawImage(((ImageObject)obj).Image, objectbounds);
        }

        LabelObject.RenderParams lrp = new LabelObject.RenderParams(drawingContext, new Common.Resolution(96, 96), false, objectbounds, flowdirection);
        obj.Render(lrp);

        VisualBrush vBrush = new VisualBrush();
        vBrush.TileMode = TileMode.None;
        vBrush.Stretch = Stretch.Fill;
        if (obj is ImageObject)
        {
            vBrush.Opacity = 0.4;
        }
        drawingContext.Close();

        vBrush.Visual = drawingVisual;

        return vBrush;
    }

请帮帮我

由于

1 个答案:

答案 0 :(得分:0)

如果要使用“变换”(TranslateTransform)移动图像,则必须在视觉画笔阶段撤消它。