System.Drawing.Graphics.Save C# (CSharp) Method

Save() public method

public Save ( ) : GraphicsState
return GraphicsState
        public GraphicsState Save()
        {
            if (stateStack == null)
            {
                stateStack = new object[MAX_GRAPHICS_STATE_STACK];
                statePos = 0;
            }

            var gsCurrentState = new GraphicsState();
            gsCurrentState.nativeState = ++statePos;

            var currentState = new CGGraphicsState();

            currentState.lastPen = LastPen;
            currentState.lastBrush = LastBrush;
            // Make sure we clone the Matrices or we will still modify
            // them after the save as they are the same objects.  Woops!!
            currentState.model = modelMatrix.Clone();
            currentState.view = viewMatrix.Clone();
            currentState.compositingQuality = CompositingQuality;
            currentState.compositingMode = CompositingMode;
            currentState.interpolationMode = interpolationMode;
            currentState.pageScale = pageScale;
            currentState.pageUnit = graphicsUnit;
            //currentState.pixelOffsetMode = PixelOffsetMode;
            currentState.smoothingMode = smoothingMode;
            //currentState.textContrast = TextContrast;
            //currentState.textRenderingHint = TextRenderingHint;
            currentState.renderingOrigin = renderingOrigin;

            currentState.clipRegion = clipRegion;

            stateStack[gsCurrentState.nativeState] = currentState;
            return gsCurrentState;
        }

Usage Example

Example #1
2
        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (applyRect.Width == 0 || applyRect.Height == 0)
            {
                // nothing to do
                return;
            }
            GraphicsState state = graphics.Save();
            if (Invert)
            {
                graphics.SetClip(applyRect);
                graphics.ExcludeClip(rect);
            }
            ColorMatrix grayscaleMatrix = new ColorMatrix(new[] {
                new[] {.3f, .3f, .3f, 0, 0},
                new[] {.59f, .59f, .59f, 0, 0},
                new[] {.11f, .11f, .11f, 0, 0},
                new float[] {0, 0, 0, 1, 0},
                new float[] {0, 0, 0, 0, 1}
            });
            using (ImageAttributes ia = new ImageAttributes())
            {
                ia.SetColorMatrix(grayscaleMatrix);
                graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
            }
            graphics.Restore(state);
        }
All Usage Examples Of System.Drawing.Graphics::Save