2

ポイントは、System.Drawing.Bitmap (.Net Framework 2.0) に変換して、コンテンツを含む WPF グリッドの単一フレームを取得する必要があるということです。

私は読んだことがVisualBrushありDrawingBrushますが、それがどのように機能するか想像できません。

任意の WPFBitmapSourceSystem.Drawing.Bitmap正常に変換できます。BitmapSourceしかし、私のグリッドからどのように受け取るのですか?

ありがとう

4

1 に答える 1

5

a を に変換するVisualには、 、およびBitmapSourceを使用できます。RenderTargetBitmapVisualBrushDrawingVisual

public BitmapSource ConvertToBitmapSource(UIElement element)
{
    var target = new RenderTargetBitmap((int)(element.RenderSize.Width), (int)(element.RenderSize.Height), 96, 96, PixelFormats.Pbgra32);
    var brush = new VisualBrush(element);

    var visual = new DrawingVisual();
    var drawingContext = visual.RenderOpen();


    drawingContext.DrawRectangle(brush, null, new Rect(new Point(0, 0),
        new Point(element.RenderSize.Width, element.RenderSize.Height)));

    drawingContext.Close();

    target.Render(visual);

    return target;
}   
于 2011-07-13T10:04:59.430 に答える