用于在WPF中渲染MeshGeometry3D的画图分辨率

时间:2015-09-29 22:31:55

标签: wpf

我在WPF中使用MeshGeometry3D可视化一些空间数据。我注意到将ImageBrush传递给DiffuseMaterial的构造函数可以快速高效地进行3D可视化和操作(比使用VisualBrush)。我的解决方案在以下代码块中,其中this.dataMeshModel是包含网格的GeometryModel3D。问题是我必须给Bitmap图像源提供非常高的分辨率(1000),以使网格看起来更好和可区分。选择这个高dpi似乎很奇怪,很容易引起内存异常。有什么建议吗?对于1000 dpi,数据模型看起来像this,对于4000 dpi,数据模型看起来像this。谢谢!

    private void assignTexture(Geometry gridGeom, double textureDPI, double gridThickness)
    {
        // rendering the grid on a DrawingVisual
        DrawingVisual dv = new DrawingVisual();
        using (var dvc = dv.RenderOpen())
        {
            dvc.DrawRectangle(Brushes.Tomato, null, gridGeom.Bounds);
            dvc.DrawGeometry(null, new Pen(Brushes.Black, gridThickness), gridGeom);
        }
        if (dv.Drawing.CanFreeze)
        {
            dv.Drawing.Freeze();
        }
        //rendering the DrawingVisual to an image
        Rect bounds = dv.ContentBounds;
        RenderTargetBitmap renderedBitmap = new RenderTargetBitmap(
            (int)(bounds.Width * this.textureDPI / 96),
            (int)(bounds.Height * this.textureDPI / 96),
            this.textureDPI,
            this.textureDPI,
            PixelFormats.Pbgra32);
        renderedBitmap.Render(dv);
        // adding the rendered image to create an imagebrush
        ImageBrush imBrush = new ImageBrush(renderedBitmap);
        //creating the material
        DiffuseMaterial dataMeshMaterial = new DiffuseMaterial(imBrush);
        this.dataMeshModel.Material = this.dataMeshMaterial;
    }

0 个答案:

没有答案