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

            int status = SafeNativeMethods.GdipCloneBitmapAreaI(
                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));
        }