0

我有图像,当我将对象从一个点移动到另一个点时,我已经为图像创建了视觉画笔。但我在视觉画笔上看不到图像。如果你看到我的矩形,它应该显示图像。

见图片: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;
    }

请帮助我

谢谢

4

1 回答 1

0

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

于 2012-09-25T16:31:17.837 回答