public DXGraphicsView() { canvas = new DXCanvas(); #if WINDOWS_UWP var displayInformation = DisplayInformation.GetForCurrentView(); canvas.Dpi = displayInformation.LogicalDpi; #endif BackgroundColor = Colors.Green; }
public override void Dispose() { if (_canvas != null) { _canvas.Dispose(); _canvas = null; } if (_bitmap != null && _disposeBitmap) { _bitmap.Dispose(); _bitmap = null; } base.Dispose(); }
public DXWicContext(int width, int height) { _bitmap = new wic.Bitmap( DXGraphicsService.FactoryImaging, width, height, wic.PixelFormat.Format32bppBGR, wic.BitmapCreateCacheOption.CacheOnLoad); var renderTargetProperties = new d2.RenderTargetProperties(d2.RenderTargetType.Default, new d2.PixelFormat(dxgi.Format.Unknown, d2.AlphaMode.Unknown), 0, 0, d2.RenderTargetUsage.None, d2.FeatureLevel.Level_DEFAULT); _renderTarget = new d2.WicRenderTarget(DXGraphicsService.SharedFactory, _bitmap, renderTargetProperties); _renderTarget.BeginDraw(); _canvas = new DXCanvas(_renderTarget); }
public void Dispose() { if (_canvas != null) { _canvas.Dispose(); _canvas = null; } if (_bitmap != null) { _bitmap.Dispose(); _bitmap = null; } if (_renderTarget != null) { _renderTarget.Dispose(); _renderTarget = null; } }
public DXBitmapExportContext(int width, int height, float displayScale = 1, int dpi = 72, bool disposeBitmap = true) : base(width, height, dpi) { _disposeBitmap = disposeBitmap; if (_default3DDevice == null) { _default3DDevice = new d3d.Device(DriverType.Hardware, d3d.DeviceCreationFlags.VideoSupport | d3d.DeviceCreationFlags.BgraSupport); // default3DDevice = new d3d.Device(DriverType.Warp, d3d.DeviceCreationFlags.BgraSupport); _default3DDevice1 = _default3DDevice.QueryInterface <d3d.Device1>(); _dxgiDevice = _default3DDevice1.QueryInterface <dxgi.Device>(); // get a reference to DXGI device _device2D = new d2.Device(_dxgiDevice); // initialize the DeviceContext - it will be the D2D render target _deviceContext = new d2.DeviceContext(_device2D, d2.DeviceContextOptions.None); } // specify a pixel format that is supported by both and WIC _pixelFormat = new d2.PixelFormat(dxgi.Format.B8G8R8A8_UNorm, d2.AlphaMode.Premultiplied); // create the d2d bitmap description using default flags var bitmapProps = new d2.BitmapProperties1(_pixelFormat, Dpi, Dpi, d2.BitmapOptions.Target | d2.BitmapOptions.CannotDraw); // create our d2d bitmap where all drawing will happen _bitmap = new d2.Bitmap1(_deviceContext, new Size2(width, height), bitmapProps); // associate bitmap with the d2d context _deviceContext.Target = _bitmap; _deviceContext.BeginDraw(); _deviceContext.Clear(new Color4 { Alpha = 0, Blue = 0, Green = 0, Red = 0 }); _canvas = new DXCanvas(_deviceContext) { DisplayScale = displayScale }; }