Exemple #1
0
        /// <include file='doc\Bitmap.uex' path='docs/doc[@for="Bitmap.Clone1"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Creates a copy of the section of this
        ///       Bitmap defined by <paramref term="rect"/> with a specified <see cref='System.Drawing.Imaging.PixelFormat'/>.
        ///    </para>
        /// </devdoc>
        // float version
        public Bitmap Clone(RectangleF rect, PixelFormat format)
        {
            IntPtr dstHandle = IntPtr.Zero;

            int status = SafeNativeMethods.GdipCloneBitmapArea(
                rect.X,
                rect.Y,
                rect.Width,
                rect.Height,
                (int)format,
                new HandleRef(this, nativeImage),
                out dstHandle);

            if (status != SafeNativeMethods.Ok || dstHandle == IntPtr.Zero)
            {
                throw SafeNativeMethods.StatusException(status);
            }

            return(Bitmap.FromGDIplus(dstHandle));
        }