3DシーンをViewport3Dからビットマップにエクスポートしたいと思います。
これを行うための明白な方法は、RenderTargetBitmapを使用することです。ただし、これを行うと、エクスポートされたビットマップの品質が画面上の画像よりも大幅に低くなります。インターネットを見回すと、RenderTargetBitmapはハードウェアレンダリングを利用していないようです。これは、レンダリングがTier0で行われることを意味します。これは、ミップマッピングなどがないため、エクスポートされた画像の品質が低下することを意味します。
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"/>
<Button Grid.Row="1" Click="Button_Click">RenderTargetBitmap!</Button>
</Grid>
</Window>
そしてこのコード:
private void Button_Click(object sender, RoutedEventArgs e)
{
RenderTargetBitmap bmp = new RenderTargetBitmap((int)viewport3D.ActualWidth,
(int)viewport3D.ActualHeight, 96, 96, PixelFormats.Default);
bmp.Render(viewport3D);
rtbImage.Source = bmp;
viewport3D.Visibility = Visibility.Collapsed;
rtbImage.Visibility = Visibility.Visible;
}