質問

下記のコードを使用しているため、DrawingVisualを使用してImageにレンダリングします。最後のRenderTargetBitmapは後でImageに追加され、画面に表示されます。

私の問題は、CanvaspixelWidthの引数がpixelHeightメソッドを望んでいます。私はそれに与えるべきですか?私はそれがそれを小さい数字を与えるならば、画像の一部はレンダリングされません。私はこれらを選ぶべき基礎について?以下のコードに1000を投稿しました。

public class ModelBeamSectionNamesInPlan : Image
{
    private readonly VisualCollection _visuals;
    public ModelBeamSectionNamesInPlan(BaseWorkspace space)
    {
        var typeface = Settings.BeamTextTypeface;
        var cultureinfo = Settings.CultureInfo;
        var flowdirection = Settings.FlowDirection;
        var beamtextsize = Settings.BeamTextSize;
        var beamtextcolor = Settings.InPlanBeamTextColor;

        beamtextcolor.Freeze();
        const double scale = 0.6;

        var drawingVisual = new DrawingVisual();
        using (var dc = drawingVisual.RenderOpen())
        {
            foreach (var beam in Building.ModelBeamsInTheElevation)
            {
                var text = beam.Section.Id;
                var ft = new FormattedText(text, cultureinfo, flowdirection,
                                           typeface, beamtextsize, beamtextcolor,
                                           null, TextFormattingMode.Display)
                {
                    TextAlignment = TextAlignment.Center
                };

                // Draw Text
                dc.DrawText(ft, space.FlipYAxis(x, y));
            }
        }

        var bmp = new RenderTargetBitmap(1000, 1000, 120, 96, PixelFormats.Pbgra32);
        bmp.Render(drawingVisual);
        Source = bmp;
    }
}
.

役に立ちましたか?

解決

描画VisualのContentBoundsプロパティを照会することができます。

CluperSevisual

の内容の境界ボックスを取得します

または

DescendantBoundsプロパティ

全てのコンテンツバウンディングボックスの統合を取得します の内容を含まないがの子孫。 引数

これがうまくいくはずです:

var bounds = drawingVisual.DescendantBounds;
var bmp = new RenderTargetBitmap(
    (int)Math.Ceiling(bounds.Width), (int)Math.Ceiling(bounds.Height),
    96, 96, PixelFormats.Pbgra32);
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top