/// <summary> /// Creates a new, blank EditableBitmap with the specified width, height, and pixel format. /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="format"></param> public EditableBitmap(int width, int height, PixelFormat format) { pixelFormatSize = Image.GetPixelFormatSize(format) / 8; stride = width * pixelFormatSize; int padding = (stride % 4); stride += padding == 0?0:4 - padding;//pad out to multiple of 4 byteArray = new SharedPinnedByteArray(stride * height); bitmap = new Bitmap(width, height, stride, format, byteArray.bitPtr); }
/// <summary> /// Creates an <see cref="EditableBitmap"/> as a view on a section of an existing <see cref="EditableBitmap"/>. /// </summary> /// <param name="source"></param> /// <param name="viewArea"></param> protected EditableBitmap(EditableBitmap source, Rectangle viewArea) { owner = source; pixelFormatSize = source.pixelFormatSize; byteArray = source.byteArray; byteArray.AddReference(); stride = source.stride; try { startOffset = source.startOffset + (stride * viewArea.Y) + (viewArea.X * pixelFormatSize); bitmap = new Bitmap(viewArea.Width, viewArea.Height, stride, source.Bitmap.PixelFormat, (IntPtr)(((int)byteArray.bitPtr) + startOffset)); } finally { if (bitmap == null) { byteArray.ReleaseReference(); } } }
/// <summary> /// Creates an <see cref="EditableBitmap"/> as a view on a section of an existing <see cref="EditableBitmap"/>. /// </summary> /// <param name="source"></param> /// <param name="viewArea"></param> protected EditableBitmap(EditableBitmap source, Rectangle viewArea) { owner=source; pixelFormatSize=source.pixelFormatSize; byteArray=source.byteArray; byteArray.AddReference(); stride = source.stride; try { startOffset=source.startOffset+(stride*viewArea.Y)+(viewArea.X*pixelFormatSize); bitmap = new Bitmap(viewArea.Width, viewArea.Height, stride, source.Bitmap.PixelFormat, (IntPtr)(((long)byteArray.bitPtr)+startOffset)); } finally { if(bitmap==null) byteArray.ReleaseReference(); } }
/// <summary> /// Creates a new, blank EditableBitmap with the specified width, height, and pixel format. /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="format"></param> public EditableBitmap(int width, int height, PixelFormat format) { pixelFormatSize = Image.GetPixelFormatSize(format) / 8; stride = width * pixelFormatSize; int padding=(stride % 4); stride += padding==0?0:4 - padding;//pad out to multiple of 4 byteArray=new SharedPinnedByteArray(stride * height); bitmap = new Bitmap(width, height, stride, format, byteArray.bitPtr); }