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(); }
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()); }
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); }
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); }
// -------------------------------------------------------------- #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); }
/// <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); } }
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()); }
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()); }
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); } }