3D 视口尺寸
我想制作我的视口的图像,但我知道的唯一方法是以下
Image myImage = new Image();
RenderTargetBitmap bmp;
bmp = new RenderTargetBitmap((int)this.Width, (int)this.Height, 96, 96, PixelFormats.Pbgra32);
bmp.Render(myViewPort);
myImage.Source = bmp;
myImage.Stretch = Stretch.Uniform;
我使用窗口的实际大小和高度来确保 bmp 变得“足够大”,即使视口占据窗口的较小部分
像这样的网格中的视口抵抗
<Grid Grid.Column="1" Name="ViewPortGrid" Background="SteelBlue" >
<Viewport3D Name="myViewPort" >
</Viewport3D>
</Grid>
我在创建 bmp 时不能使用 ViewPortGrid.Widht/Height 或 myViewPort.Widht/Height 因为它们是 NaN。
有没有更好的方法来创建视口图像?
有没有办法获得视口的真实大小,以便 RenderTargetBitmap 的创建等于视口的大小(使用窗口大小使图像比需要的大得多)?
/斯特凡
I want to make a image of my viewport but the only way I know is the following
Image myImage = new Image();
RenderTargetBitmap bmp;
bmp = new RenderTargetBitmap((int)this.Width, (int)this.Height, 96, 96, PixelFormats.Pbgra32);
bmp.Render(myViewPort);
myImage.Source = bmp;
myImage.Stretch = Stretch.Uniform;
I am using the windows actual size and height to be sure that the bmp get "big enough" even if the viewport takes up a smaller part of the window
The viewport resist in a grid like this
<Grid Grid.Column="1" Name="ViewPortGrid" Background="SteelBlue" >
<Viewport3D Name="myViewPort" >
</Viewport3D>
</Grid>
I can not use ViewPortGrid.Widht/Height or myViewPort.Widht/Height when creating the bmp becosue these are NaN.
Are there better ways of creating an image of the viewport ?
Is there a way of getting the true size of the viewport so the creating of the RenderTargetBitmap is equal to the size of the viewport (using the window size makes the image much bigger than needed) ?
/Stefan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 .ActualWidth 和 .ActualHeight 属性。
这与 WPF 中的渲染和处理方式有关,这与 WinForms 完全不同。
请参阅:
http://learnwpf.com/post/2007/03/14/Why-is-the-WidthHeight-Property-for-many-Elements-e28098NaNe28099-in-WPF.aspx
Try using the .ActualWidth and .ActualHeight properties.
This has to do with the way things are rendered and handled in WPF, which is completely different from WinForms.
See:
http://learnwpf.com/post/2007/03/14/Why-is-the-WidthHeight-Property-for-many-Elements-e28098NaNe28099-in-WPF.aspx