public System.Drawing.Bitmap FlushToBitmap() { byte[] bits = new byte[width * height * 4]; memStream = new System.IO.MemoryStream(bits); var stream = new SharpDX.WIC.WICStream(wicFactory, memStream); // Initialize a Jpeg encoder with this stream var encoder = new SharpDX.WIC.BitmapEncoder(wicFactory, SharpDX.WIC.ContainerFormatGuids.Bmp); encoder.Initialize(stream); // Create a Frame encoder var bitmapFrameEncode = new SharpDX.WIC.BitmapFrameEncode(encoder); bitmapFrameEncode.Initialize(); bitmapFrameEncode.SetSize(width, height); var pixelFormatGuid = SharpDX.WIC.PixelFormat.FormatDontCare; bitmapFrameEncode.SetPixelFormat(ref pixelFormatGuid); bitmapFrameEncode.WriteSource(wicBitmap); bitmapFrameEncode.Commit(); encoder.Commit(); bitmapFrameEncode.Dispose(); encoder.Dispose(); stream.Dispose(); return((System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(memStream)); }
public void Dispose() { if (stream != null) { stream.Dispose(); stream = null; } if (d2dRenderTarget != null) { d2dRenderTarget.Dispose(); d2dRenderTarget = null; } if (wicBitmap != null) { wicBitmap.Dispose(); wicBitmap = null; } if (d2dFactory != null) { d2dFactory.Dispose(); d2dFactory = null; } if (wicFactory != null) { wicFactory.Dispose(); wicFactory = null; } if (memStream != null) { memStream.Dispose(); } }
public static void SaveToTiff(SharpDX.WIC.ImagingFactory imagingFactory, UnmanagedImage image, string filename, Guid format, int bytesPerPixel) { var file = new System.IO.FileStream(filename, System.IO.FileMode.Create); var stream = new SharpDX.WIC.WICStream(imagingFactory, file); var encoder = new SharpDX.WIC.BitmapEncoder(imagingFactory, SharpDX.WIC.ContainerFormatGuids.Tiff); encoder.Initialize(stream); var bitmapFrameEncode = new SharpDX.WIC.BitmapFrameEncode(encoder); //bitmapFrameEncode.Options.TiffCompressionMethod = SharpDX.WIC.TiffCompressionOption.None; bitmapFrameEncode.Initialize(); bitmapFrameEncode.SetSize(image.Width, image.Height); bitmapFrameEncode.SetPixelFormat(ref format); bitmapFrameEncode.WritePixels(image.Height, image.DataIntPtr, image.Width * bytesPerPixel); bitmapFrameEncode.Commit(); encoder.Commit(); bitmapFrameEncode.Dispose(); encoder.Dispose(); stream.Dispose(); file.Close(); file.Dispose(); }