protected void Dispose(bool disposing) { if (disposed) { return; } bitmap.Dispose(); byteArray.ReleaseReference(); disposed = true; //Set managed object refs to null if explicitly disposing, so that they can be cleaned up by the GC. if (disposing) { owner = null; bitmap = null; } }
/// <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(); } } }