示例#1
0
        public Bitmap ArgbToBitmap()
        {
            BytesBitmap bb = new BytesBitmap(Width, Height, PixelFormat.Format32bppArgb);

            for (int p = 0, bp = 0; p < Width * Height; p++)
            {
                int data = Data[p];
                bb.Bits[bp++] = (byte)data;           // blue
                bb.Bits[bp++] = (byte)(data >> 8);    // green
                bb.Bits[bp++] = (byte)(data >> 16);   // red
                bb.Bits[bp++] = (byte)(data >> 24);   // alpha
            }
            return(bb.GetBitmapCopy());
        }
示例#2
0
        public void ArgbFromBitmap(Bitmap bmp)
        {
            BytesBitmap bb = new BytesBitmap(bmp.Width, bmp.Height, PixelFormat.Format32bppArgb);
            Graphics    gr = Graphics.FromImage(bb.Bitmap);

            gr.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);

            Width  = bmp.Width;
            Height = bmp.Height;
            Data   = new int[Width * Height];

            for (int p = 0, bp = 0; p < Width * Height; p++, bp += 4)
            {
                //                alpha                       red                      green              blue
                Data[p] = (bb.Bits[bp + 3] << 24) | (bb.Bits[bp + 2] << 16) | (bb.Bits[bp + 1] << 8) | bb.Bits[bp];
            }
        }