public DirectBitmap(int width, int height)
 {
     Width      = width;
     Height     = height;
     Bits       = new int[width * height];
     BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
     Bitmap     = new Bitmap(width, height, width * 4, PixelFormat.Format32bppPArgb,
                             BitsHandle.AddrOfPinnedObject());
 }
 private void CreateBitmap(int width, int height)
 {
     Width      = width;
     Height     = height;
     Bits       = new byte[width * height * 4];
     BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
     Bitmap     = new Bitmap(width, height, width * 4, PixelFormat.Format32bppPArgb,
                             BitsHandle.AddrOfPinnedObject());
     MakeBlackBitmap();
 }
Exemplo n.º 3
0
        public zBitmap(Bitmap bitmap)
        {
            var image = bitmap;

            Width      = image.Width;
            Height     = image.Height;
            Bits       = new int[image.Width * image.Height];
            BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
            Bitmap     = new Bitmap(image.Width, image.Height, image.Width * 4, PixelFormat.Format32bppPArgb,
                                    BitsHandle.AddrOfPinnedObject());
        }
        public DirectBitmap(Bitmap bitmap)
        {
            Width  = bitmap.Width;
            Height = bitmap.Height;
            bitmap = bitmap.Clone(new Rectangle(0, 0, Width, Height), PixelFormat.Format32bppPArgb);

            Bits       = bitmap.ToByteArrayARGB();
            BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
            Bitmap     = new Bitmap(Width, Height, Width * 4, PixelFormat.Format32bppPArgb,
                                    BitsHandle.AddrOfPinnedObject());
        }
Exemplo n.º 5
0
        public zBitmap(string path)
        {
            var image = (Bitmap)Image.FromFile(path);

            Width      = image.Width;
            Height     = image.Height;
            Bits       = new int[image.Width * image.Height];
            BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
            Bitmap     = new Bitmap(image.Width, image.Height, image.Width * 4, PixelFormat.Format32bppPArgb,
                                    BitsHandle.AddrOfPinnedObject());
            Path = path;
            SetImage(path);
        }
Exemplo n.º 6
0
 public DirectBitmap(int width, int height)
 {
     Width      = width;
     Height     = height;
     Bits       = new byte[width * height];
     BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
     Bitmap     = new Bitmap(width, height, width, PixelFormat.Format8bppIndexed, BitsHandle.AddrOfPinnedObject());
     PtrHandle  = GCHandle.ToIntPtr(BitsHandle);
 }
Exemplo n.º 7
0
        // --------------------------------------------------------------
        #region CONSTRUCTORS
        // --------------------------------------------------------------

        /// <summary>
        /// Create a new bitmap image
        /// </summary>
        /// <param name="width">Image width</param>
        /// <param name="height">Image height</param>
        public DirectBitmap(int width, int height)
        {
            // set the image width
            Width = width;

            // set the image height
            Height = height;

            // create the pixels array for the image
            Bits = new Int32[width * height];

            // allocate the memory for the image
            BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);

            // create a new bitmap image in the allocated area of the memory
            Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppPArgb, BitsHandle.AddrOfPinnedObject());

            // set the image empty (fully transparent)
            Graphics.FromImage(Bitmap).Clear(Color.Transparent);
        }
Exemplo n.º 8
0
        /// <summary>
        /// DirectBitmap from a bitmap image
        /// </summary>
        /// <param name="bmp">Bitmap image</param>
        public DirectBitmap(Bitmap bmp)
        {
            // make sure we have a valid image
            if (bmp == null)
            {
                return;
            }

            // set the image width
            Width = bmp.Width;

            // set the image height
            Height = bmp.Height;

            // create the pixels array for the image
            Bits = new Int32[Width * Height];

            // allocate the memory for the image
            BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);

            // create a new bitmap image in the allocated area of the memory
            Bitmap = new Bitmap(Width, Height, Width * 4, PixelFormat.Format32bppPArgb, BitsHandle.AddrOfPinnedObject());

            // initialize the graphics object on the image
            using (Graphics g = Graphics.FromImage(Bitmap))
            {
                // set the image empty (fully transparent)
                g.Clear(Color.Transparent);

                // draw the image
                g.DrawImage(bmp, 0, 0);
            }
        }
Exemplo n.º 9
0
 public DirectBitmap(Bitmap bitmap)
 {
     Width  = bitmap.Width;
     Height = bitmap.Height;
     Bits   = new int[Width * Height];
     for (int i = 0; i < Height; i++)
     {
         for (int j = 0; j < Width; j++)
         {
             var pixel = bitmap.GetPixel(j, i);
             int R     = pixel.R;
             int G     = pixel.G;
             int B     = pixel.B;
             Bits[i * Width + j] = Color.FromArgb(R, G, B).ToArgb();
         }
     }
     BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
     Bitmap     = new Bitmap(Width, Height, Width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject());
 }
Exemplo n.º 10
0
        public DirectBitmap(int[] bits, int width, int height)
        {
            Width  = width;
            Height = height;
            Bits   = new int[bits.Length];
            int idx = 0;

            foreach (int i in bits)
            {
                Bits[idx++] = i;
            }
            BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
            Bitmap     = new Bitmap(width, height, width * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject());
        }
Exemplo n.º 11
0
        public DirectBitmap(string filename)
        {
            var bitmap = new Bitmap(filename);

            Width      = bitmap.Width;
            Height     = bitmap.Height;
            Bits       = new Int32[Width * Height];
            BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
            Bitmap     = new Bitmap(Width, Height, Width * 4, PixelFormat.Format32bppPArgb, BitsHandle.AddrOfPinnedObject());

            using (Graphics g = Graphics.FromImage(Bitmap))
            {
                g.DrawImage(bitmap, 0, 0, bitmap.Width, bitmap.Height);
            }
        }