BiliRanking.Core.Fubang.transferOneARGBChannelFromOneBitmapToAnother C# (CSharp) Method

transferOneARGBChannelFromOneBitmapToAnother() public static method

public static transferOneARGBChannelFromOneBitmapToAnother ( Bitmap source, Bitmap dest, ChannelARGB sourceChannel, ChannelARGB destChannel ) : void
source System.Drawing.Bitmap
dest System.Drawing.Bitmap
sourceChannel ChannelARGB
destChannel ChannelARGB
return void
        public static void transferOneARGBChannelFromOneBitmapToAnother(
            Bitmap source,
            Bitmap dest,
            ChannelARGB sourceChannel,
            ChannelARGB destChannel)
        {
            if (source.Size != dest.Size)
                throw new ArgumentException();
            Rectangle r = new Rectangle(Point.Empty, source.Size);
            BitmapData bdSrc = source.LockBits(r, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
            BitmapData bdDst = dest.LockBits(r, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            unsafe
            {
                byte* bpSrc = (byte*)bdSrc.Scan0.ToPointer();
                byte* bpDst = (byte*)bdDst.Scan0.ToPointer();
                bpSrc += (int)sourceChannel;
                bpDst += (int)destChannel;
                for (int i = r.Height * r.Width; i > 0; i--)
                {
                    *bpDst = *bpSrc;
                    bpSrc += 4;
                    bpDst += 4;
                }
            }
            source.UnlockBits(bdSrc);
            dest.UnlockBits(bdDst);
        }