Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF中的渲染位图问题_Wpf_Rendertargetbitmap - Fatal编程技术网

WPF中的渲染位图问题

WPF中的渲染位图问题,wpf,rendertargetbitmap,Wpf,Rendertargetbitmap,实际上,我必须从Viewport3D打印视图,显然,我使用的是RenderTargetBitmap。问题是,如果渲染图像的分辨率变高,场景中的一些三角形就不会出现在最终图像上 例如,我的视口可以是1024*768,我使用的渲染目标位图的分辨率将是视口分辨率的3倍 我已经用某种方式解决了这个问题。。。事实上,当我使用大比例尺时,三角形不会出现。如果我减小渲染目标位图的大小,它将包含所有内容 实际上,我在96dpi上有或多或少的1024*768。如果我想在300dpi上留下深刻印象,我需要获得一个

实际上,我必须从
Viewport3D
打印视图,显然,我使用的是
RenderTargetBitmap
。问题是,如果渲染图像的分辨率变高,场景中的一些三角形就不会出现在最终图像上

例如,我的
视口
可以是1024*768,我使用的
渲染目标位图
的分辨率将是
视口
分辨率的3倍

我已经用某种方式解决了这个问题。。。事实上,当我使用大比例尺时,三角形不会出现。如果我减小渲染目标位图的大小,它将包含所有内容

实际上,我在96dpi上有或多或少的1024*768。如果我想在300dpi上留下深刻印象,我需要获得一个巨大的图像,因此我希望避免最后的解决方案

一些代码:

public static RenderTargetBitmap CaptureEcran(Viewport3D p_viewPort, int p_scale)
    {
        RenderTargetBitmap l_bmp;
        p_scale = p_scale > 5 ? 5 : p_scale;
        l_bmp = new RenderTargetBitmap(p_scale * Convert.ToInt32(p_viewPort.ActualWidth), p_scale * Convert.ToInt32(p_viewPort.ActualHeight), p_scale * 96.0, p_scale * 96.0, PixelFormats.Pbgra32);

        DrawingVisual vis = new DrawingVisual();
        DrawingContext dc = vis.RenderOpen();
        dc.DrawRectangle(System.Windows.Media.Brushes.White, null, new Rect(0, 0, p_scale * p_viewPort.ActualWidth, p_scale * p_viewPort.ActualHeight));
        dc.Close();

        l_bmp.Render(vis);
        p_viewPort.UpdateLayout();
        l_bmp.Render(p_viewPort);
        return l_bmp;
    }

public static void SaveImage(RenderTargetBitmap renderTargetBitmap, string m_impression)
    {
        System.Windows.Forms.FolderBrowserDialog l_fBD = new System.Windows.Forms.FolderBrowserDialog();
        l_fBD.ShowDialog();
        string l_path = l_fBD.SelectedPath + "\\" + CurrentUser() + "__" + CurrentDate() + "__." + m_impression.ToLower();
        FileStream stream = new FileStream(l_path, FileMode.Create);

        BitmapEncoder l_encoder = null;
        switch(m_impression){
            case "PNG":
                PngBitmapEncoder l_png = new PngBitmapEncoder();
                l_encoder = l_png;
                break;
            case "JPEG":
                JpegBitmapEncoder l_jpeg = new JpegBitmapEncoder();
                l_jpeg.QualityLevel = 30;
                l_encoder = l_jpeg;
                break;
        }
        l_encoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
        l_encoder.Save(stream);
        stream.Close();
    }
我的电话是:

SaveImage(CaptureEcran(m_viewPortCourant.ViewPort3D,5), m_impression);

当m_impression为.png或.jpg时,它最终通过使用包含视口并绘制到DrawingContext中的VisualBrush来工作

DrawingVisual vis = new DrawingVisual();
DrawingContext dc = vis.RenderOpen(); 
VisualBrush sourceBrush = new VisualBrush(p_viewPort);

dc.DrawRectangle(System.Windows.Media.Brushes.White, null, new Rect(0, 0, p_viewPort.ActualWidth * p_scale, p_viewPort.ActualHeight * p_scale));
dc.DrawRectangle(sourceBrush, null, new Rect(new System.Windows.Point(0, 0), new Vector(p_viewPort.ActualWidth, p_viewPort.ActualHeight)));
dc.Close();    

l_bmp.Render(vis);