相关疑难解决方法(0)

从System.Drawing.Bitmap加载WPF BitmapImage

我有一个a的实例,System.Drawing.Bitmap并希望以一种形式将它提供给我的WPF应用程序System.Windows.Media.Imaging.BitmapImage.

对此最好的方法是什么?

c# wpf bitmap

217
推荐指数
8
解决办法
21万
查看次数

RenderTargetBitmap和Viewport3D - 质量问题

我想将一个3D场景从Viewport3D导出到位图.

显而易见的方法是使用RenderTargetBitmap - 但是当我这样做时,导出的位图的质量明显低于屏幕上的图像.环顾四周,似乎RenderTargetBitmap没有利用硬件渲染.这意味着渲染在第0层完成.这意味着没有mip-mapping等,因此降低了导出图像的质量.

有谁知道如何以屏幕质量导出Viewport3D的位图?

澄清

虽然下面给出的示例没有显示这一点,但我最终需要将Viewport3D的位图导出到文件中.据我所知,唯一的方法是将图像转换为从BitmapSource派生的东西.下面的Cplotts显示使用RenderTargetBitmap提高导出质量可以改善图像,但由于渲染仍然在软件中完成,因此速度极慢.

有没有办法使用硬件渲染将渲染的3D场景导出到文件?当然应该可以吗?

你可以看到这个xaml的问题:

<Window x:Class="RenderTargetBitmapProblem.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="400" Width="500">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Viewport3D Name="viewport3D">
            <Viewport3D.Camera>
                <PerspectiveCamera Position="0,0,3"/>
            </Viewport3D.Camera>
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <AmbientLight Color="White"/>
                </ModelVisual3D.Content>
            </ModelVisual3D>
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <GeometryModel3D>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D Positions="-1,-10,0  1,-10,0  -1,20,0  1,20,0"
                                            TextureCoordinates="0,1 0,0 1,1 1,0"
                                            TriangleIndices="0,1,2 1,3,2"/>
                        </GeometryModel3D.Geometry>
                        <GeometryModel3D.Material>
                            <DiffuseMaterial>
                                <DiffuseMaterial.Brush>
                                    <ImageBrush ImageSource="http://www.wyrmcorp.com/galleries/illusions/Hermann%20Grid.png"
                                                TileMode="Tile" Viewport="0,0,0.25,0.25"/>
                                </DiffuseMaterial.Brush>
                            </DiffuseMaterial>
                        </GeometryModel3D.Material>
                    </GeometryModel3D>
                </ModelVisual3D.Content>
                <ModelVisual3D.Transform>
                    <RotateTransform3D>
                        <RotateTransform3D.Rotation>
                            <AxisAngleRotation3D Axis="1,0,0" Angle="-82"/>
                        </RotateTransform3D.Rotation>
                    </RotateTransform3D>
                </ModelVisual3D.Transform>
            </ModelVisual3D>
        </Viewport3D>
        <Image Name="rtbImage" Visibility="Collapsed"/> …
Run Code Online (Sandbox Code Playgroud)

.net c# 3d wpf rendertargetbitmap

16
推荐指数
1
解决办法
8272
查看次数

RenderTargetBitmap + Resource'd VisualBrush =不完整的图像

我在"Visual to RenderTargetBitmap"问题上找到了新的转折!

我正在为设计师渲染WPF的预览.这意味着我需要获取WPF视觉效果并将其渲染为位图,而不会显示该视觉效果.有一个很好的小方法来做它喜欢在这里看到它

private static BitmapSource CreateBitmapSource(FrameworkElement visual)
{
    Border b = new Border { Width = visual.Width, Height = visual.Height };
    b.BorderBrush = Brushes.Black;
    b.BorderThickness = new Thickness(1);
    b.Background = Brushes.White;
    b.Child = visual;

    b.Measure(new Size(b.Width, b.Height));
    b.Arrange(new Rect(b.DesiredSize));

    RenderTargetBitmap rtb = new RenderTargetBitmap(
                                (int)b.ActualWidth,
                                (int)b.ActualHeight,
                                96,
                                96,
                                PixelFormats.Pbgra32);

    // intermediate step here to ensure any VisualBrushes are rendered properly
    DrawingVisual dv = new DrawingVisual();
    using (var dc = dv.RenderOpen())
    {
        var vb = new VisualBrush(b);
        dc.DrawRectangle(vb, null, …
Run Code Online (Sandbox Code Playgroud)

wpf visualbrush rendertargetbitmap

8
推荐指数
1
解决办法
3473
查看次数

标签 统计

wpf ×3

c# ×2

rendertargetbitmap ×2

.net ×1

3d ×1

bitmap ×1

visualbrush ×1