public virtual void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) { applyRect = IntersectRectangle(applyBitmap.Size, rect); if (applyRect.Width == 0 || applyRect.Height == 0) { // nothing to do return; } bbb = new BitmapBuffer(applyBitmap, applyRect); try { bbb.Lock(); for (int y = 0; y < bbb.Height; y++) { for (int x = 0; x < bbb.Width; x++) { if (parent.Contains(applyRect.Left + x, applyRect.Top + y) ^ Invert) { IteratePixel(x, y); } } } } finally { bbb.DrawTo(graphics, applyRect.Location); bbb.Dispose(); bbb = null; } }
public void Dispose() { buf.Dispose(); buf = null; bmp.Dispose(); bmp = null; }
public void Dispose() { if (bb != null) { bb.Dispose(); } bb = null; }
// Graphics / Buffer helper functions public unsafe int[,] GetColorDistribution(SoftwareBitmap haystack, Color needle, int[] tolerance, int sparcity = 2) { int w = haystack.PixelWidth; int h = haystack.PixelHeight; int r = needle.R; int g = needle.G; int b = needle.B; int[,] dA = new int[w * h, 2]; int dAPointer = 0; BitmapBuffer buffer = haystack.LockBuffer(BitmapBufferAccessMode.Read); BitmapPlaneDescription bufferLayout = buffer.GetPlaneDescription(0); IMemoryBufferReference reference = buffer.CreateReference(); ((IMemoryBufferByteAccess)reference).GetBuffer(out byte *bufferData, out uint capacity); int pos; for (int x = 0; x < w; x += sparcity) { for (int y = 0; y < h; y += sparcity) { pos = bufferLayout.StartIndex + bufferLayout.Stride * y + 4 * x; int rC = bufferData[pos + 2]; int gC = bufferData[pos + 1]; int bC = bufferData[pos]; if (Math.Abs(rC - r) <= tolerance[0] && Math.Abs(gC - g) <= tolerance[1] && Math.Abs(bC - b) <= tolerance[2]) { dA[dAPointer, 0] = x; dA[dAPointer, 1] = y; dAPointer++; } } } dAPointer--; reference.Dispose(); buffer.Dispose(); int[,] distributionArray = new int[dAPointer + 1, 2]; for (int p = dAPointer; p >= 0; p--) { distributionArray[p, 0] = dA[p, 0]; distributionArray[p, 1] = dA[p, 1]; } return(distributionArray); }
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) { magnificationFactor = GetFieldValueAsInt(FieldType.MAGNIFICATION_FACTOR); applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); bbbSrc = new BitmapBuffer(applyBitmap, applyRect); try { bbbSrc.Lock(); base.Apply(graphics, applyBitmap, applyRect, renderMode); } finally { bbbSrc.Dispose(); bbbSrc = null; } }
protected virtual void Dispose(bool disposing) { if (disposing) { if (_dynamicRenderEventPublisher != null) { _dynamicRenderEventPublisher.Cancel(); _dynamicRenderEventPublisher.Dispose(); _dynamicRenderEventPublisher = null; } if (_vtkRenderWindow != null) { _vtkRenderWindow.Dispose(); _vtkRenderWindow = null; } if (_vtkRenderer != null) { _vtkRenderer.Dispose(); _vtkRenderer = null; } if (_sceneGraphRoot != null) { _sceneGraphRoot.Dispose(); _sceneGraphRoot = null; } if (_imageBuffer != null) { _imageBuffer.Dispose(); _imageBuffer = null; } if (_overlayBuffer != null) { _overlayBuffer.Dispose(); _overlayBuffer = null; } if (_finalBuffer != null) { _finalBuffer.Dispose(); _finalBuffer = null; } } }
public unsafe void SetPixelColor(SoftwareBitmap swBmp, int x, int y, Color color) { BitmapBuffer buffer = swBmp.LockBuffer(BitmapBufferAccessMode.Write); BitmapPlaneDescription bufferLayout = buffer.GetPlaneDescription(0); if (x >= 0 && x < bufferLayout.Width && y >= 0 && y < bufferLayout.Height) { using (IMemoryBufferReference reference = buffer.CreateReference()) { ((IMemoryBufferByteAccess)reference).GetBuffer(out byte *bufferData, out uint capacity); bufferData[bufferLayout.StartIndex + bufferLayout.Stride * y + 4 * x + 0] = color.B; bufferData[bufferLayout.StartIndex + bufferLayout.Stride * y + 4 * x + 1] = color.G; bufferData[bufferLayout.StartIndex + bufferLayout.Stride * y + 4 * x + 2] = color.R; bufferData[bufferLayout.StartIndex + bufferLayout.Stride * y + 4 * x + 3] = color.A; } } buffer.Dispose(); }
public unsafe Color GetPixelColor(SoftwareBitmap swBmp, int x, int y) { BitmapBuffer buffer = swBmp.LockBuffer(BitmapBufferAccessMode.Read); BitmapPlaneDescription bufferLayout = buffer.GetPlaneDescription(0); Color color = new Color(); if (x >= 0 && x < bufferLayout.Width && y >= 0 && y < bufferLayout.Height) { using (IMemoryBufferReference reference = buffer.CreateReference()) { ((IMemoryBufferByteAccess)reference).GetBuffer(out byte *bufferData, out uint capacity); color.B = bufferData[bufferLayout.StartIndex + bufferLayout.Stride * y + 4 * x + 0]; color.G = bufferData[bufferLayout.StartIndex + bufferLayout.Stride * y + 4 * x + 1]; color.R = bufferData[bufferLayout.StartIndex + bufferLayout.Stride * y + 4 * x + 2]; color.A = bufferData[bufferLayout.StartIndex + bufferLayout.Stride * y + 4 * x + 3]; } } buffer.Dispose(); return(color); }
Dispose() { m_rowIndex = -1; // Prevents further reading/writing m_rowReadableCapacity = 0; m_rowWriteableCapacity = 0; if (m_locked) { m_byteAccess.Unlock(); m_byteAccess = null; m_locked = false; } if (m_buffer != null) { m_buffer.Dispose(); m_buffer = null; } GC.SuppressFinalize(this); }
public void Dispose() { _bb?.Dispose(); _bb = null; }
void DrawImageForPrint(object sender, PrintPageEventArgs e) { PrintOptionsDialog pod = printOptionsDialog; ContentAlignment alignment = pod.AllowPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft; if (conf.OutputPrintInverted) { // Invert Bitmap BitmapBuffer bb = new BitmapBuffer((Bitmap)image, false); bb.Lock(); for (int y = 0; y < bb.Height; y++) { for (int x = 0; x < bb.Width; x++) { Color color = bb.GetColorAt(x, y); Color invertedColor = Color.FromArgb(color.A, color.R ^ 255, color.G ^ 255, color.B ^ 255); bb.SetColorAt(x, y, invertedColor); } } bb.Dispose(); } RectangleF pageRect = e.PageSettings.PrintableArea; GraphicsUnit gu = GraphicsUnit.Pixel; RectangleF imageRect = image.GetBounds(ref gu); // rotate the image if it fits the page better if (pod.AllowPrintRotate) { if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) || (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height)) { image.RotateFlip(RotateFlipType.Rotate90FlipNone); imageRect = image.GetBounds(ref gu); if (alignment.Equals(ContentAlignment.TopLeft)) { alignment = ContentAlignment.TopRight; } } } RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height);; // scale the image to fit the page better if (pod.AllowPrintEnlarge || pod.AllowPrintShrink) { SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, false); if ((pod.AllowPrintShrink && resizedRect.Width < printRect.Width) || pod.AllowPrintEnlarge && resizedRect.Width > printRect.Width) { printRect.Size = resizedRect; } } // prepare timestamp float dateStringWidth = 0; float dateStringHeight = 0; if (conf.OutputPrintTimestamp) { Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular); string dateString = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); dateStringWidth = e.Graphics.MeasureString(dateString, f).Width; dateStringHeight = e.Graphics.MeasureString(dateString, f).Height; e.Graphics.DrawString(dateString, f, Brushes.Black, pageRect.Width / 2 - (dateStringWidth / 2), pageRect.Height - dateStringHeight); } // align the image printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Width, pageRect.Height - dateStringHeight * 2), alignment); e.Graphics.DrawImage(image, printRect, imageRect, GraphicsUnit.Pixel); }