Ejemplo n.º 1
0
        /// <summary>
        /// Dispose of the image
        /// </summary>
        public void Dispose()
        {
            // has the image already been disposed?
            if (Disposed)
            {
                return;
            }

            // flag the image as disposed
            Disposed = true;

            // free the memory used by the image
            BitsHandle.Free();

            // remove the image data array
            Bits = null;

            // destroy the bitmap object
            DeleteObject(Bitmap.GetHbitmap());

            // dispose the image for good
            Bitmap.Dispose();
            Bitmap = null;

            // Suppress finalization.
            GC.SuppressFinalize(this);
        }
 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());
 }
Ejemplo n.º 3
0
 public void Dispose()
 {
     if (Disposed)
     {
         return;
     }
     Disposed = true;
     Bitmap.Dispose();
     BitsHandle.Free();
 }
Ejemplo n.º 4
0
 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();
 }
Ejemplo n.º 5
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());
        }
Ejemplo n.º 6
0
        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());
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
 public void Resize(int width, int height)
 {
     Bitmap.Dispose();
     BitsHandle.Free();
     CreateBitmap(width, height);
 }
Ejemplo n.º 9
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);
 }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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());
 }
Ejemplo n.º 13
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());
        }
Ejemplo n.º 14
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);
            }
        }