RestoreGraphScale() public method

public RestoreGraphScale ( ) : void
return void
Ejemplo n.º 1
0
    CopyGraphToBitmap
    (
        Int32 bitmapWidthPx,
        Int32 bitmapHeightPx
    )
    {
        const String MethodName = "CopyGraphToBitmap";

        this.ArgumentChecker.CheckArgumentPositive(MethodName, "bitmapWidthPx",
            bitmapWidthPx);

        this.ArgumentChecker.CheckArgumentPositive(MethodName, "bitmapHeightPx",
            bitmapHeightPx);

        CheckIfLayingOutGraph(MethodName);

        // Save the current vertex locations.

        LayoutSaver oLayoutSaver = new LayoutSaver(this.Graph);

        // Adjust the control's graph scale so that the graph's vertices and
        // edges will be the same relative size in the image that they are in
        // the control.

        GraphImageScaler oGraphImageScaler = new GraphImageScaler(this);

        oGraphImageScaler.SetGraphScale(bitmapWidthPx, bitmapHeightPx,
            WpfGraphicsUtil.GetScreenDpi(this).Width);

        // Adjust the control's transforms so that the image will be centered
        // on the same point on the graph that the control is centered on.

        GraphImageCenterer oGraphImageCenterer = new GraphImageCenterer(this);

        oGraphImageCenterer.CenterGraphImage(
            new Size(bitmapWidthPx, bitmapHeightPx) );

        // Transform the graph's layout to the specified size.

        Double dOriginalActualWidth = this.ActualWidth;
        Double dOriginalActualHeight = this.ActualHeight;

        Rect oBitmapRectangle = new Rect(0, 0,
            (Double)bitmapWidthPx, (Double)bitmapHeightPx);

        TransformLayout(oBitmapRectangle);

        Debug.Assert(m_eLayoutState == LayoutState.Stable);

        DrawGraph(oBitmapRectangle);

        System.Drawing.Bitmap oBitmap = WpfGraphicsUtil.VisualToBitmap(this,
            bitmapWidthPx, bitmapHeightPx);

        // Restore the original layout.
        //
        // NOTE:
        //
        // Don't try calling TransformLayout() again using the original
        // rectangle.  The first call to TransformLayout() lost "resolution" if
        // the layout was transformed to a smaller rectangle, and attempting to
        // reverse the transform will yield poor results.

        oLayoutSaver.RestoreLayout();

        oGraphImageScaler.RestoreGraphScale();

        oBitmapRectangle =
            new Rect(0, 0, dOriginalActualWidth, dOriginalActualHeight);

        Debug.Assert(m_eLayoutState == LayoutState.Stable);

        DrawGraph(oBitmapRectangle);

        oGraphImageCenterer.RestoreCenter();

        return (oBitmap);
    }