将 RenderTargetBitmap 与 Viewport3D 结合使用
我使用 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)。
如何强制渲染 UIElement3D 对象,或者为什么在创建新视口与打印现有 XAML 视口实例时它不起作用?
在这里您可以找到重现我的问题的示例解决方案 http://cid-df67ca3f85229bd1.office.live.com/ self.aspx/Development/WpfApplication2.zip
问候 罗兰
I use Viewport3d and display my 3D Elements with inherited UIElement3D classes... Now I want to make different images of my viewport (different views). That means I have to make a new viewport3d at runtime and apply my specific view for the image on it..
see the following code:
' 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
The first picture (test_xamlviewport.png) is shown correctly, but the second picture where I create my own Viewport3D Object and print it is empty (test_localviewport.png).
How can I force to Render my UIElement3D Objects or why it doesn't work if i make a new Viewport vs print the existing XAML viewport instance?
Here you find a sample solution which reproduce my problem
http://cid-df67ca3f85229bd1.office.live.com/self.aspx/Development/WpfApplication2.zip
Regards
Roland
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论