1
に割り当てることなく、viewport3DのrenderTargetBitmap私はコードでViewport3Dを作成します。WPF、C#の、ウィンドウ
Viewport3D CurViewport3D = new Viewport3D();
CurViewport3D = CreateViewportWithContent(); //fill the viewport with some content
BitmapSource bmp;
var renderTargetBitmap = new RenderTargetBitmap(600, 300, 96, 96, PixelFormats.Default);
renderTargetBitmap.Render(CurViewport3D);
bmp = (BitmapSource)renderTargetBitmap;
PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(bmp));
using (Stream stm = File.Create("outp.png")){ png.Save(stm);}
しかし残念ながらoutp.pngはどんな内容のない空です。 場合、私は、ウィンドウにビューポートを適用しています:
MainGrid.Children.Add(CurViewport3D); //MainGrid is part of the window
すべてが完璧に動作します。 outp.pngは空ではありません。 ビューポートをウィンドウに適用せずに正しい画像を得るために何をすべきか考えている人はいますか?
問題が解決しました。
int width = 500;
int height = 300;
CurViewport3D.Width = width;
CurViewport3D.Height = height;
CurViewport3D.Measure(new Size(width, height));
CurViewport3D.Arrange(new Rect(0, 0, width, height));