我使用Viewport3d并使用继承的UIElement3D类显示我的3D元素...现在我想制作视口的不同图像(不同视图)。这意味着我必须在运行时创建一个新的viewport3d并在其上应用我的特定视图..
请参阅以下代码:
' Start creating Image
Dim bitmap As New RenderTargetBitmap(800,
800,
96,
96,
PixelFormats.Default)
'--------------------
'Render xamlViewport works perfect
bitmap.Render(xamlViewport)
Using stream As FileStream = New FileStream("C:\\temp\\test_xamlviewport.png", FileMode.Create)
Dim encoder As New PngBitmapEncoder
encoder.Frames.Add(BitmapFrame.Create(bitmap))
encoder.Save(stream)
End Using
'---------------------
'Render local Viewport don't work
Dim oViewport As New Viewport3D
oViewport.Height = 800
oViewport.Width = 800
oViewport.Children.Add(New C3DCuboid())
oViewport.Camera = New PerspectiveCamera(New Point3D(4, 7, 6), New Vector3D(-4, -7, -6), New Vector3D(0, 1, 0), 45)
Dim oVisual As New ModelVisual3D
oVisual.Content = New DirectionalLight(Colors.White, New Vector3D(-1, -2, -3))
oViewport.Children.Add(oVisual)
oViewport.Measure(New Size(800, 800))
oViewport.Arrange(New Rect(New Size(800, 800)))
bitmap = New RenderTargetBitmap(800,
800,
96,
96,
PixelFormats.Default)
bitmap.Render(oViewport)
Using stream As FileStream = New FileStream("C:\\temp\\test_localviewport.png", FileMode.Create)
Dim encoder As New PngBitmapEncoder
encoder.Frames.Add(BitmapFrame.Create(bitmap))
encoder.Save(stream)
End Using
第一张图片(test_xamlviewport.png)显示正确,但我创建自己的Viewport3D对象并打印它的第二张图片是空的(test_localviewport.png)。
如果我创建一个新的Viewport vs打印现有的XAML视口实例,我如何强制渲染我的UIElement3D对象或者为什么它不起作用?
在这里,您可以找到一个可以重现我的问题的示例解决方案 http://cid-df67ca3f85229bd1.office.live.com/self.aspx/Development/WpfApplication2.zip
此致 罗兰