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

Restore() public method

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

            if (state.nativeState > statePos)
                return;

            if (state.nativeState >= MAX_GRAPHICS_STATE_STACK)
                throw new OutOfMemoryException();

            var gstate = (CGGraphicsState)stateStack[state.nativeState];
            LastPen = gstate.lastPen;
            LastBrush = gstate.lastBrush;
            modelMatrix = gstate.model;
            viewMatrix = gstate.view;

            CompositingMode = gstate.compositingMode;
            CompositingQuality = gstate.compositingQuality;
            interpolationMode = gstate.interpolationMode;
            pageScale = gstate.pageScale;
            graphicsUnit = gstate.pageUnit;
            //PixelOffsetMode = gstate.pixelOffsetMode;
            SmoothingMode = gstate.smoothingMode;
            //TextContrast = gstate.textContrast;
            //TextRenderingHint = gstate.textRenderingHint;
            renderingOrigin = gstate.renderingOrigin;
            clipRegion = gstate.clipRegion;

            // re-apply our ModelView to the graphics context
            applyModelView();

            statePos = state.nativeState - 1;
        }

Usage 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::Restore