C# 内存法复制图像bitmap

/**
         * 内存法复制图片
         * */
        private void copyBitmap(Bitmap bmpSrc, Bitmap bmpDest)
        {
            int w = bmpSrc.Width, h = bmpSrc.Height;
            PixelFormat format = bmpSrc.PixelFormat;

            // Lock the bitmap's bits.  锁定位图
            Rectangle rect = new Rectangle(0, 0, w, h);
            BitmapData bmpDataSrc =
                bmpSrc.LockBits(rect, ImageLockMode.ReadOnly,
                format);
            // Get the address of the first line.获取首行地址
            IntPtr ptrSrc = bmpDataSrc.Scan0;

            BitmapData bmpDataDest =
                bmpDest.LockBits(rect, ImageLockMode.WriteOnly,
                format);
            IntPtr ptrDest = bmpDataDest.Scan0;


            // Declare an array to hold the bytes of the bitmap.定义数组保存位图
            int bytes = Math.Abs(bmpDataSrc.Stride) * h;
            byte[] rgbValues = new byte[bytes];

            // Copy the RGB values into the array.复制RGB值到数组
            System.Runtime.InteropServices.Marshal.Copy(ptrSrc, rgbValues, 0, bytes);
            //复制到新图
            System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptrDest, bytes);

            // Unlock the bits.解锁
            bmpSrc.UnlockBits(bmpDataSrc);
            bmpDest.UnlockBits(bmpDataDest);
        }


//注意使用 bmpSRC.Dispose();