Beispiel #1
0
        public void Complement(Rectangle rect)
        {
            var gprect = new GPRECT(rect);
            int status = SafeNativeMethods.Gdip.GdipCombineRegionRectI(new HandleRef(this, _nativeRegion), ref gprect, CombineMode.Complement);

            SafeNativeMethods.Gdip.CheckStatus(status);
        }
Beispiel #2
0
        public Matrix(Rectangle rect, Point[] plgpts)
        {
            if (plgpts == null)
            {
                throw new ArgumentNullException("plgpts");
            }
            if (plgpts.Length != 3)
            {
                throw SafeNativeMethods.Gdip.StatusException(2);
            }
            IntPtr handle = SafeNativeMethods.Gdip.ConvertPointToMemory(plgpts);

            try
            {
                IntPtr zero   = IntPtr.Zero;
                GPRECT gprect = new GPRECT(rect);
                int    status = SafeNativeMethods.Gdip.GdipCreateMatrix3I(ref gprect, new HandleRef(null, handle), out zero);
                if (status != 0)
                {
                    throw SafeNativeMethods.Gdip.StatusException(status);
                }
                this.nativeMatrix = zero;
            }
            finally
            {
                Marshal.FreeHGlobal(handle);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
        /// </summary>
        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
        {
            IntPtr metafile = IntPtr.Zero;

            int status;

            if (frameRect.IsEmpty)
            {
                status = SafeNativeMethods.Gdip.GdipRecordMetafileFileName(fileName,
                                                                           new HandleRef(null, referenceHdc),
                                                                           unchecked ((int)type),
                                                                           NativeMethods.NullHandleRef,
                                                                           unchecked ((int)frameUnit),
                                                                           description,
                                                                           out metafile);
            }
            else
            {
                GPRECT gprect = new GPRECT(frameRect);
                status = SafeNativeMethods.Gdip.GdipRecordMetafileFileNameI(fileName,
                                                                            new HandleRef(null, referenceHdc),
                                                                            unchecked ((int)type),
                                                                            ref gprect,
                                                                            unchecked ((int)frameUnit),
                                                                            description,
                                                                            out metafile);
            }

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

            SetNativeImage(metafile);
        }
Beispiel #4
0
        public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string desc)
        {
            IntSecurity.ObjectFromWin32Handle.Demand();

            IntPtr metafile = IntPtr.Zero;

            int status;

            if (frameRect.IsEmpty)
            {
                status = SafeNativeMethods.Gdip.GdipRecordMetafile(new HandleRef(null, referenceHdc),
                                                                   unchecked ((int)type),
                                                                   NativeMethods.NullHandleRef,
                                                                   unchecked ((int)MetafileFrameUnit.GdiCompatible),
                                                                   desc,
                                                                   out metafile);
            }
            else
            {
                GPRECT gprect = new GPRECT(frameRect);
                status = SafeNativeMethods.Gdip.GdipRecordMetafileI(new HandleRef(null, referenceHdc),
                                                                    unchecked ((int)type),
                                                                    ref gprect,
                                                                    unchecked ((int)frameUnit),
                                                                    desc,
                                                                    out metafile);
            }

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

            SetNativeImage(metafile);
        }
Beispiel #5
0
        // int version
        /// <include file='doc\Matrix.uex' path='docs/doc[@for="Matrix.Matrix3"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.Drawing.Drawing2D.Matrix'/> class to the geometrical transform
        ///       defined by the specified rectangle and array of points.
        ///    </para>
        /// </devdoc>
        public Matrix(Rectangle rect, Point[] plgpts)
        {
            if (plgpts == null)
            {
                throw new ArgumentNullException("plgpts");
            }
            if (plgpts.Length != 3)
            {
                throw SafeNativeMethods.StatusException(SafeNativeMethods.InvalidParameter);
            }

            IntPtr buf = SafeNativeMethods.ConvertPointToMemory(plgpts);

            IntPtr matrix = IntPtr.Zero;

            GPRECT gprect = new GPRECT(rect);
            int    status = SafeNativeMethods.GdipCreateMatrix3I(ref gprect, new HandleRef(null, buf), out matrix);

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

            this.nativeMatrix = matrix;

            Marshal.FreeHGlobal(buf);
        }
Beispiel #6
0
        public LinearGradientBrush(Rectangle rect, Color color1, Color color2, LinearGradientMode linearGradientMode)
        {
            // The valid values for LinearGgradientMode are 0 to 3.
            if (!ClientUtils.IsEnumValid(linearGradientMode, unchecked ((int)linearGradientMode), (int)LinearGradientMode.Horizontal, (int)LinearGradientMode.BackwardDiagonal))
            {
                throw new InvalidEnumArgumentException(nameof(linearGradientMode), unchecked ((int)linearGradientMode), typeof(LinearGradientMode));
            }

            if (rect.Width == 0 || rect.Height == 0)
            {
                throw new ArgumentException(SR.Format(SR.GdiplusInvalidRectangle, rect.ToString()));
            }

            var    gpRect = new GPRECT(rect);
            IntPtr nativeBrush;
            int    status = SafeNativeMethods.Gdip.GdipCreateLineBrushFromRectI(ref gpRect,
                                                                                color1.ToArgb(),
                                                                                color2.ToArgb(),
                                                                                unchecked ((int)linearGradientMode),
                                                                                (int)WrapMode.Tile,
                                                                                out nativeBrush);

            SafeNativeMethods.Gdip.CheckStatus(status);

            SetNativeBrushInternal(nativeBrush);
        }
Beispiel #7
0
        /// <include file='doc\Metafile.uex' path='docs/doc[@for="Metafile.Metafile38"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.Drawing.Imaging.Metafile'/> class with the
        ///       specified filename.
        ///    </para>
        /// </devdoc>
        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit,
                        EmfType type, string description)
        {
            IntSecurity.ObjectFromWin32Handle.Demand();

            IntPtr metafile = IntPtr.Zero;

            int status;

            if (frameRect.IsEmpty)
            {
                status = SafeNativeMethods.GdipRecordMetafileStream(new GPStream(stream), new HandleRef(null, referenceHdc), (int)type,
                                                                    NativeMethods.NullHandleRef, (int)frameUnit, description, out metafile);
            }
            else
            {
                GPRECT gprect = new GPRECT(frameRect);
                status = SafeNativeMethods.GdipRecordMetafileStreamI(new GPStream(stream), new HandleRef(null, referenceHdc), (int)type,
                                                                     ref gprect, (int)frameUnit, description, out metafile);
            }

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

            SetNativeImage(metafile);
        }
Beispiel #8
0
        public LinearGradientBrush(Rectangle rect, Color color1, Color color2, LinearGradientMode linearGradientMode)
        {
            //validate the LinearGradientMode enum
            //valid values are 0x0 to 0x3
            if (!ClientUtils.IsEnumValid(linearGradientMode, unchecked ((int)linearGradientMode), (int)LinearGradientMode.Horizontal, (int)LinearGradientMode.BackwardDiagonal))
            {
                throw new InvalidEnumArgumentException("linearGradientMode", unchecked ((int)linearGradientMode), typeof(LinearGradientMode));
            }

            //validate the rect
            if (rect.Width == 0 || rect.Height == 0)
            {
                throw new ArgumentException(SR.Format(SR.GdiplusInvalidRectangle, rect.ToString()));
            }

            GPRECT gpRect = new GPRECT(rect);
            IntPtr nativeBrush;
            int    status = SafeNativeMethods.Gdip.GdipCreateLineBrushFromRectI(ref gpRect,
                                                                                color1.ToArgb(),
                                                                                color2.ToArgb(),
                                                                                unchecked ((int)linearGradientMode),
                                                                                (int)WrapMode.Tile,
                                                                                out nativeBrush);

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

            SetNativeBrushInternal(nativeBrush);
        }
Beispiel #9
0
        public LinearGradientBrush(Rectangle rect, Color color1, Color color2, float angle, bool isAngleScaleable)
        {
            //validate the rect
            if (rect.Width == 0 || rect.Height == 0)
            {
                throw new ArgumentException(SR.Format(SR.GdiplusInvalidRectangle, rect.ToString()));
            }

            GPRECT gprect = new GPRECT(rect);
            IntPtr nativeBrush;
            int    status = SafeNativeMethods.Gdip.GdipCreateLineBrushFromRectWithAngleI(ref gprect,
                                                                                         color1.ToArgb(),
                                                                                         color2.ToArgb(),
                                                                                         angle,
                                                                                         isAngleScaleable,
                                                                                         (int)WrapMode.Tile,
                                                                                         out nativeBrush);

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

            SetNativeBrushInternal(nativeBrush);
        }
Beispiel #10
0
        public void Exclude(Rectangle rect)
        {
            GPRECT gprect = new GPRECT(rect);
            int    status = SafeNativeMethods.Gdip.GdipCombineRegionRectI(new HandleRef(this, this.nativeRegion), ref gprect, CombineMode.Exclude);

            if (status != 0)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }
        }
Beispiel #11
0
        // int version
        /// <include file='doc\Region.uex' path='docs/doc[@for="Region.Complement1"]/*' />
        /// <devdoc>
        ///    Updates this <see cref='System.Drawing.Region'/> to the portion of the
        ///    specified <see cref='System.Drawing.Rectangle'/> that does not intersect with this <see cref='System.Drawing.Region'/>.
        /// </devdoc>
        public void Complement(Rectangle rect)
        {
            GPRECT gprect = new GPRECT(rect);
            int    status = SafeNativeMethods.Gdip.GdipCombineRegionRectI(new HandleRef(this, nativeRegion), ref gprect, CombineMode.Complement);

            if (status != SafeNativeMethods.Gdip.Ok)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }
        }
        public void AddString(string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat format)
        {
            GPRECT gprect = new GPRECT(layoutRect);
            int    status = SafeNativeMethods.Gdip.GdipAddPathStringI(new HandleRef(this, this.nativePath), s, s.Length, new HandleRef(family, (family != null) ? family.NativeFamily : IntPtr.Zero), style, emSize, ref gprect, new HandleRef(format, (format != null) ? format.nativeFormat : IntPtr.Zero));

            if (status != 0)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }
        }
Beispiel #13
0
        public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData)
        {
            var gprect = new GPRECT(rect);
            int status = SafeNativeMethods.Gdip.GdipBitmapLockBits(new HandleRef(this, nativeImage), ref gprect,
                                                                   flags, format, bitmapData);

            SafeNativeMethods.Gdip.CheckStatus(status);

            return(bitmapData);
        }
Beispiel #14
0
        public Region(Rectangle rect)
        {
            IntPtr region = IntPtr.Zero;
            var    gprect = new GPRECT(rect);
            int    status = SafeNativeMethods.Gdip.GdipCreateRegionRectI(ref gprect, out region);

            SafeNativeMethods.Gdip.CheckStatus(status);

            SetNativeRegion(region);
        }
Beispiel #15
0
        public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData)
        {
            GPRECT gprect = new GPRECT(rect);
            int    status = SafeNativeMethods.Gdip.GdipBitmapLockBits(new HandleRef(this, base.nativeImage), ref gprect, flags, format, bitmapData);

            if (status != 0)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }
            return(bitmapData);
        }
Beispiel #16
0
        public Region(Rectangle rect)
        {
            IntPtr zero   = IntPtr.Zero;
            GPRECT gprect = new GPRECT(rect);
            int    status = SafeNativeMethods.Gdip.GdipCreateRegionRectI(ref gprect, out zero);

            if (status != 0)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }
            this.SetNativeRegion(zero);
        }
Beispiel #17
0
        public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData)
        {
            var gprect = new GPRECT(rect);
            int status = SafeNativeMethods.Gdip.GdipBitmapLockBits(new HandleRef(this, nativeImage), ref gprect,
                                                                   flags, format, bitmapData);

            // libgdiplus has the wrong error code mapping for this state.
            if (status == 7)
            {
                status = 8;
            }
            SafeNativeMethods.Gdip.CheckStatus(status);

            return(bitmapData);
        }
Beispiel #18
0
        public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData)
        {
            Contract.Ensures(Contract.Result <BitmapData>() != null);

            GPRECT gprect = new GPRECT(rect);
            int    status = SafeNativeMethods.Gdip.GdipBitmapLockBits(new HandleRef(this, nativeImage), ref gprect,
                                                                      flags, format, bitmapData);

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

            return(bitmapData);
        }
Beispiel #19
0
        public Region(Rectangle rect)
        {
            IntPtr region = IntPtr.Zero;

            GPRECT gprect = new GPRECT(rect);

            int status = SafeNativeMethods.Gdip.GdipCreateRegionRectI(ref gprect, out region);

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

            SetNativeRegion(region);
        }
        public LinearGradientBrush(System.Drawing.Rectangle rect, Color color1, Color color2, float angle, bool isAngleScaleable)
        {
            IntPtr zero = IntPtr.Zero;

            if ((rect.Width == 0) || (rect.Height == 0))
            {
                throw new ArgumentException(System.Drawing.SR.GetString("GdiplusInvalidRectangle", new object[] { rect.ToString() }));
            }
            GPRECT gprect = new GPRECT(rect);
            int    status = SafeNativeMethods.Gdip.GdipCreateLineBrushFromRectWithAngleI(ref gprect, color1.ToArgb(), color2.ToArgb(), angle, isAngleScaleable, 0, out zero);

            if (status != 0)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }
            base.SetNativeBrushInternal(zero);
        }
        public void AddString(string s, FontFamily family, int style, float emSize,
                              Point origin, StringFormat format)
        {
            var rect = new GPRECT(origin.X, origin.Y, 0, 0);

            int status = SafeNativeMethods.Gdip.GdipAddPathStringI(new HandleRef(this, nativePath),
                                                                   s,
                                                                   s.Length,
                                                                   new HandleRef(family, (family != null) ? family.NativeFamily : IntPtr.Zero),
                                                                   style,
                                                                   emSize,
                                                                   ref rect,
                                                                   new HandleRef(format, (format != null) ? format.nativeFormat : IntPtr.Zero));

            if (status != SafeNativeMethods.Gdip.Ok)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }
        }
        public LinearGradientBrush(System.Drawing.Rectangle rect, Color color1, Color color2, LinearGradientMode linearGradientMode)
        {
            if (!System.Drawing.ClientUtils.IsEnumValid(linearGradientMode, (int)linearGradientMode, 0, 3))
            {
                throw new InvalidEnumArgumentException("linearGradientMode", (int)linearGradientMode, typeof(LinearGradientMode));
            }
            if ((rect.Width == 0) || (rect.Height == 0))
            {
                throw new ArgumentException(System.Drawing.SR.GetString("GdiplusInvalidRectangle", new object[] { rect.ToString() }));
            }
            IntPtr zero   = IntPtr.Zero;
            GPRECT gprect = new GPRECT(rect);
            int    status = SafeNativeMethods.Gdip.GdipCreateLineBrushFromRectI(ref gprect, color1.ToArgb(), color2.ToArgb(), (int)linearGradientMode, 0, out zero);

            if (status != 0)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }
            base.SetNativeBrushInternal(zero);
        }
        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
        {
            int num;

            System.Drawing.IntSecurity.ObjectFromWin32Handle.Demand();
            IntPtr zero = IntPtr.Zero;

            if (frameRect.IsEmpty)
            {
                num = SafeNativeMethods.Gdip.GdipRecordMetafileStream(new GPStream(stream), new HandleRef(null, referenceHdc), (int)type, System.Drawing.NativeMethods.NullHandleRef, (int)frameUnit, description, out zero);
            }
            else
            {
                GPRECT gprect = new GPRECT(frameRect);
                num = SafeNativeMethods.Gdip.GdipRecordMetafileStreamI(new GPStream(stream), new HandleRef(null, referenceHdc), (int)type, ref gprect, (int)frameUnit, description, out zero);
            }
            if (num != 0)
            {
                throw SafeNativeMethods.Gdip.StatusException(num);
            }
            base.SetNativeImage(zero);
        }
Beispiel #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
        /// </summary>
        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
        {
            // Called in order to emulate exception behavior from netfx related to invalid file paths.
            Path.GetFullPath(fileName);

            IntPtr metafile = IntPtr.Zero;

            int status;

            if (frameRect.IsEmpty)
            {
                status = SafeNativeMethods.Gdip.GdipRecordMetafileFileName(fileName,
                                                            new HandleRef(null, referenceHdc),
                                                            unchecked((int)type),
                                                            NativeMethods.NullHandleRef,
                                                            unchecked((int)frameUnit),
                                                            description,
                                                            out metafile);
            }
            else
            {
                GPRECT gprect = new GPRECT(frameRect);
                status = SafeNativeMethods.Gdip.GdipRecordMetafileFileNameI(fileName,
                                                             new HandleRef(null, referenceHdc),
                                                             unchecked((int)type),
                                                             ref gprect,
                                                             unchecked((int)frameUnit),
                                                             description,
                                                             out metafile);
            }

            if (status != SafeNativeMethods.Gdip.Ok)
                throw SafeNativeMethods.Gdip.StatusException(status);

            SetNativeImage(metafile);
        }