예제 #1
0
        private void Dispose(bool disposing)
        {
#if DEBUG && FINALIZATION_WATCH
            if (!disposing && _nativeGraphics != IntPtr.Zero)
            {
                Debug.WriteLine("System.Drawing.Graphics: ***************************************************");
                Debug.WriteLine("System.Drawing.Graphics: Object Disposed through finalization:\n" + allocationSite);
            }
#endif
            while (_previousContext != null)
            {
                // Dispose entire stack.
                GraphicsContext context = _previousContext.Previous;
                _previousContext.Dispose();
                _previousContext = context;
            }

            if (NativeGraphics != IntPtr.Zero)
            {
                try
                {
                    if (_nativeHdc != IntPtr.Zero) // avoid a handle leak.
                    {
                        ReleaseHdc();
                    }

                    if (PrintingHelper is DeviceContext printerDC)
                    {
                        printerDC.Dispose();
                        _printingHelper = null;
                    }

#if DEBUG
                    int status = !Gdip.Initialized ? Gdip.Ok :
#endif
                    Gdip.GdipDeleteGraphics(new HandleRef(this, NativeGraphics));

#if DEBUG
                    Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
#endif
                }
                catch (Exception ex) when(!ClientUtils.IsSecurityOrCriticalException(ex))
                {
                }
                finally
                {
                    NativeGraphics = IntPtr.Zero;
                }
            }
        }
 public GraphicsContainer BeginContainer()
 {
     GraphicsContext context = new GraphicsContext(this);
     int state = 0;
     int status = SafeNativeMethods.Gdip.GdipBeginContainer2(new HandleRef(this, this.NativeGraphics), out state);
     if (status != 0)
     {
         context.Dispose();
         throw SafeNativeMethods.Gdip.StatusException(status);
     }
     context.State = state;
     this.PushContext(context);
     return new GraphicsContainer(state);
 }
예제 #3
0
        /// <devdoc>
        ///     Disposes this and all contexts up the stack.
        /// </devdoc>
        public void Dispose(bool disposing)
        {
            if (_nextContext != null)
            {
                // Dispose all contexts up the stack since they are relative to this one and its state will be invalid.
                _nextContext.Dispose();
                _nextContext = null;
            }

            if (_clipRegion != null)
            {
                _clipRegion.Dispose();
                _clipRegion = null;
            }
        }
 public GraphicsContainer BeginContainer(Rectangle dstrect, Rectangle srcrect, GraphicsUnit unit)
 {
     GraphicsContext context = new GraphicsContext(this);
     int state = 0;
     GPRECT dstRect = new GPRECT(dstrect);
     GPRECT srcRect = new GPRECT(srcrect);
     int status = SafeNativeMethods.Gdip.GdipBeginContainerI(new HandleRef(this, this.NativeGraphics), ref dstRect, ref srcRect, (int) unit, out state);
     if (status != 0)
     {
         context.Dispose();
         throw SafeNativeMethods.Gdip.StatusException(status);
     }
     context.State = state;
     this.PushContext(context);
     return new GraphicsContainer(state);
 }
예제 #5
0
        public GraphicsContainer BeginContainer(RectangleF dstrect, RectangleF srcrect, GraphicsUnit unit) {
            GraphicsContext context = new GraphicsContext(this);
            int state = 0;

            GPRECTF dstf = dstrect.ToGPRECTF();
            GPRECTF srcf = srcrect.ToGPRECTF();

            int status = SafeNativeMethods.Gdip.GdipBeginContainer(new HandleRef(this, this.NativeGraphics), ref dstf,
                                                    ref srcf, unchecked((int) unit), out state);

            if (status != SafeNativeMethods.Gdip.Ok) {
                context.Dispose();
                throw SafeNativeMethods.Gdip.StatusException(status);
            }

            context.State = state;
            PushContext(context);

            return new GraphicsContainer(state);
        }
예제 #6
0
        public GraphicsState Save() {
            GraphicsContext context = new GraphicsContext(this);
            int state = 0;

            int status = SafeNativeMethods.Gdip.GdipSaveGraphics(new HandleRef(this, this.NativeGraphics), out state);

            if (status != SafeNativeMethods.Gdip.Ok) {
                context.Dispose();
                throw SafeNativeMethods.Gdip.StatusException(status);
            }

            context.State = state;
            context.IsCumulative = true;
            PushContext(context);

            return new GraphicsState(state);
        }