0

奇妙な問題ですが、RenderTargetBitmap 関数が ViewPort3D の左側の余白をレンダリングしていることがわかりました。ビットマップ (この場合は PNG) を保存すると、最終イメージの左側にギャップがあり、右側が同じ量だけ切り取られます。ViewPort3D のサイズは、高さ 550 ピクセル、幅 1024 ピクセルです。RenderTargetBitmap メソッドで同じ寸法を使用します。なぜ定義された境界の外に出るのか、私は困惑しています。

    <Grid>
    <Button Content="Save Snapshot" HorizontalAlignment="Left" Name="btnSaveSnapshot"  VerticalAlignment="Top" Width="100" Margin="8,8,0,0"/>
    <Viewport3D Name="vp3dTiles" Height="550" Width="1024" UseLayoutRounding="True"  HorizontalAlignment="Center" VerticalAlignment="Bottom" >
        <Viewport3D.Camera>
            <PerspectiveCamera Position="384,1750,174" LookDirection="0,-.65,-0.25"  UpDirection="0,0,1"  FieldOfView="65"/>
        </Viewport3D.Camera>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <Model3DGroup>
                    <AmbientLight Color="white" />
                    <GeometryModel3D>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D Positions="0,0,0 768,0,0 768,1408,0 0,1408,0 " TriangleIndices="0 1 3 1 2 3" TextureCoordinates="0,0 760,0 760,1408 0,1408 "/>                             
                        </GeometryModel3D.Geometry>
                        <GeometryModel3D.Material>                               
                            <DiffuseMaterial>
                                <DiffuseMaterial.Brush>
                                    <ImageBrush ViewportUnits="Absolute" TileMode="Tile" ImageSource="FlorVintage_FINAL.png" Viewport="0,0,768,1408" ViewboxUnits="Absolute" Stretch="None" AlignmentY="Top" RenderOptions.BitmapScalingMode="NearestNeighbor" AlignmentX="Left" />
                                </DiffuseMaterial.Brush> 
                            </DiffuseMaterial>
                        </GeometryModel3D.Material>

                    </GeometryModel3D>
                </Model3DGroup>
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>

</Grid>

そして背後にあるコード (VB で - 申し訳ありません):

    Private Sub btnSaveSnapshot_Click(sender As Object, e As RoutedEventArgs) Handles btnSaveSnapshot.Click
    Dim bmp As New RenderTargetBitmap(1024, 550, 96, 96, PixelFormats.Pbgra32)
    bmp.Render(Me.vp3dTiles)
    Dim png As New PngBitmapEncoder()
    png.Frames.Add(BitmapFrame.Create(bmp))
    Using stm As Stream = File.Create(My.Settings.FileSavePath & "\" & "TestSnapshot.png")
        png.Save(stm)
    End Using
End Sub

それが入っているコンテナ(グリッド)が問題かもしれないと思っています。

4

2 に答える 2