public WICBitmapCanvas (WIC.Bitmap bmp, D2D1.RenderTargetProperties properties, Direct2DFactories factories = null) : base (new D2D1.WicRenderTarget ((factories ?? Direct2DFactories.Shared).D2DFactory, bmp, properties), factories) { this.Bmp = bmp; this.scale = properties.DpiX / 96.0; var bmpSize = bmp.Size; this.size = new Size (bmpSize.Width / scale, bmpSize.Height / scale); }
public WICBitmapSourceImage (WIC.BitmapSource bmp, double scale, Direct2DFactories factories = null) { if (bmp == null) throw new ArgumentNullException ("bmp"); this.bmp = bmp; this.scale = scale; this.factories = factories ?? Direct2DFactories.Shared; }
private MemoryStream GetBitmapAsStream(WIC.Bitmap wicBitmap) { int width = wicBitmap.Size.Width; int height = wicBitmap.Size.Height; var ms = new MemoryStream(); using (var stream = new WIC.WICStream( this.WicFactory, ms)) { using (var encoder = new WIC.PngBitmapEncoder(WicFactory)) { encoder.Initialize(stream); using (var frameEncoder = new WIC.BitmapFrameEncode(encoder)) { frameEncoder.Initialize(); frameEncoder.SetSize(width, height); var format = WIC.PixelFormat.Format32bppBGRA; frameEncoder.SetPixelFormat(ref format); frameEncoder.WriteSource(wicBitmap); frameEncoder.Commit(); } encoder.Commit(); } } ms.Position = 0; return ms; }