我有一个 WPF 应用程序生成一些报告。我需要从 WindowService 启动此应用程序,而我目前正在从作为 LocalSystem 运行的服务执行该应用程序。除 Pie 3d 外,所有渲染均已正确完成,显示在 Viewport3D 对象中。这是显示行为的代码提取:
static class VisualSaver
    {
        public static void Save(Visual v, int width, int height, string file,Brush background)
        {
            RenderTargetBitmap bmp = new RenderTargetBitmap(
                        width, height, 96, 96, PixelFormats.Pbgra32);
            Rectangle vRect = new Rectangle();
            vRect.Width = width;
            vRect.Height = height;
            vRect.Fill = background;
            vRect.Arrange(new Rect(0, 0, vRect.Width, vRect.Height));
            bmp.Render(vRect);
            bmp.Render(v);
            PngBitmapEncoder png = new PngBitmapEncoder();
            png.Frames.Add(BitmapFrame.Create(bmp));
            using (Stream stm = File.Create(file))
            {
                png.Save(stm);
            }
        }
    }
这是调用代码:
VisualSaver.Save(viewport,310,340,PathExtension.GetTempFileWithExtension("png"),Brushes.White);
是的,视口是正确测量/排列的。
从 3d 对象的非交互式应用程序渲染是否有一些限制,我在 Windows7 - 2008 服务器环境中。? 有什么解决方法吗?