ICanvasImage GetSourceBitmap(PerDeviceResources resources) { #if WINDOWS_UWP if (CurrentSource == SourceMode.VirtualBitmap) { var virtualBitmap = resources.VirtualBitmap; var pixels = virtualBitmap.SizeInPixels; resources.AddMessage("VirtualBitmap (dpi: 96, size: {0}, pixels: {1},{2} ->\n", virtualBitmap.Size, pixels.Width, pixels.Height); return(resources.VirtualBitmap); } #endif CanvasBitmap bitmap; switch (CurrentSource) { case SourceMode.DefaultDpiBitmap: bitmap = resources.DefaultDpiBitmap; break; case SourceMode.HighDpiBitmap: bitmap = resources.HighDpiBitmap; break; case SourceMode.LowDpiBitmap: bitmap = resources.LowDpiBitmap; break; default: bitmap = null; break; } if (bitmap != null) { var pixels = bitmap.SizeInPixels; resources.AddMessage("Bitmap (dpi: {0}, size: {1}, pixels: {2},{3}) ->\n", bitmap.Dpi, bitmap.Size, pixels.Width, pixels.Height); } return(bitmap); }
ICanvasImage WrapSourceWithIntermediateImage(PerDeviceResources resources, IntermediateMode mode) { switch (mode) { case IntermediateMode.ImageEffect: // We can either feed our graphics through an image effect... resources.SaturationEffect.Source = GetSourceBitmap(resources) ?? WrapSourceWithIntermediateImage(resources, IntermediateMode.None); resources.AddMessage("SaturationEffect ->\n"); return(resources.SaturationEffect); case IntermediateMode.CommandList: var cl = new CanvasCommandList(resources.ResourceCreator); using (var ds = cl.CreateDrawingSession()) { DrawSourceGraphic(resources, ds, 0); } resources.AddMessage("CommandList ->\n"); return(cl); case IntermediateMode.ImageEffectInCommandList: var cl2 = new CanvasCommandList(resources.ResourceCreator); using (var ds = cl2.CreateDrawingSession()) { ds.DrawImage(WrapSourceWithIntermediateImage(resources, IntermediateMode.ImageEffect)); } resources.AddMessage("CommandList ->\n"); return(cl2); default: // ... or draw them into a rendertarget. var renderTarget = GetIntermediateRenderTarget(resources, mode); using (var ds = renderTarget.CreateDrawingSession()) { DrawSourceGraphic(resources, ds, 0); } var pixels = renderTarget.SizeInPixels; resources.AddMessage("RenderTarget (dpi: {0}, size: {1}, pixels: {2},{3}) ->\n", renderTarget.Dpi, renderTarget.Size, pixels.Width, pixels.Height); return(renderTarget); } }
void DrawViaImageBrush(CanvasDrawingSession ds) { imageBrush.Image = WrapSourceWithIntermediateImage(mainDeviceResources, CurrentIntermediate); imageBrush.SourceRectangle = new Rect(0, 0, testSize, testSize); imageBrush.Transform = Matrix3x2.CreateTranslation(testOffset, testOffset); ds.FillRectangle(testOffset, testOffset, testSize, testSize, imageBrush); mainDeviceResources.AddMessage("CanvasImageBrush ->\nCanvasControl (dpi: {0})", ds.Dpi); }
void DrawToOutput(PerDeviceResources resources, CanvasDrawingSession ds) { if (CurrentIntermediate == IntermediateMode.None) { // We can either draw directly to the output... DrawSourceGraphic(resources, ds, testOffset); } else { // Or go via an intermediate such as a rendertarget or image effect. var intermediateImage = WrapSourceWithIntermediateImage(resources, CurrentIntermediate); ds.DrawImage(intermediateImage, testOffset, testOffset); } resources.AddMessage("{0} (dpi: {1})", CurrentOutput, ds.Dpi); }
CanvasBitmap GetSourceBitmap(PerDeviceResources resources) { CanvasBitmap bitmap; switch (CurrentSource) { case SourceMode.DefaultDpiBitmap: bitmap = resources.DefaultDpiBitmap; break; case SourceMode.HighDpiBitmap: bitmap = resources.HighDpiBitmap; break; case SourceMode.LowDpiBitmap: bitmap = resources.LowDpiBitmap; break; default: bitmap = null; break; } if (bitmap != null) { resources.AddMessage("Bitmap (dpi: {0}, size: {1}, pixels: {2}) ->\n", bitmap.Dpi, bitmap.Size, bitmap.SizeInPixels); } return(bitmap); }
void DrawSourceGraphic(PerDeviceResources resources, CanvasDrawingSession ds, float offset) { var source = GetSourceBitmap(resources); if (source != null) { // We can either draw a precreated bitmap... ds.DrawImage(source, offset, offset); } else { // ... or directly draw some shapes. ds.FillRectangle(offset, offset, testSize, testSize, Colors.Gray); ds.DrawLine(offset, offset, offset + testSize, offset + testSize, Colors.Red); ds.DrawLine(offset + testSize, offset, offset, offset + testSize, Colors.Red); ds.DrawRectangle(offset + 0.5f, offset + 0.5f, testSize - 1, testSize - 1, Colors.Blue); ds.DrawText("DPI test", new Vector2(offset + testSize / 2), Colors.Blue, resources.TextFormat); resources.AddMessage("DrawingSession ->\n"); } }
ICanvasImage GetSourceBitmap(PerDeviceResources resources) { #if WINDOWS_UWP if (CurrentSource == SourceMode.VirtualBitmap) { var virtualBitmap = resources.VirtualBitmap; var pixels = virtualBitmap.SizeInPixels; resources.AddMessage("VirtualBitmap (dpi: 96, size: {0}, pixels: {1},{2} ->\n", virtualBitmap.Size, pixels.Width, pixels.Height); return resources.VirtualBitmap; } #endif CanvasBitmap bitmap; switch (CurrentSource) { case SourceMode.DefaultDpiBitmap: bitmap = resources.DefaultDpiBitmap; break; case SourceMode.HighDpiBitmap: bitmap = resources.HighDpiBitmap; break; case SourceMode.LowDpiBitmap: bitmap = resources.LowDpiBitmap; break; default: bitmap = null; break; } if (bitmap != null) { var pixels = bitmap.SizeInPixels; resources.AddMessage("Bitmap (dpi: {0}, size: {1}, pixels: {2},{3}) ->\n", bitmap.Dpi, bitmap.Size, pixels.Width, pixels.Height); } return bitmap; }
ICanvasImage WrapSourceWithIntermediateImage(PerDeviceResources resources, IntermediateMode mode) { switch (mode) { case IntermediateMode.ImageEffect: // We can either feed our graphics through an image effect... resources.SaturationEffect.Source = GetSourceBitmap(resources) ?? WrapSourceWithIntermediateImage(resources, IntermediateMode.None); resources.AddMessage("SaturationEffect ->\n"); return resources.SaturationEffect; case IntermediateMode.CommandList: var cl = new CanvasCommandList(resources.ResourceCreator); using (var ds = cl.CreateDrawingSession()) { DrawSourceGraphic(resources, ds, 0); } resources.AddMessage("CommandList ->\n"); return cl; case IntermediateMode.ImageEffectInCommandList: var cl2 = new CanvasCommandList(resources.ResourceCreator); using (var ds = cl2.CreateDrawingSession()) { ds.DrawImage(WrapSourceWithIntermediateImage(resources, IntermediateMode.ImageEffect)); } resources.AddMessage("CommandList ->\n"); return cl2; default: // ... or draw them into a rendertarget. var renderTarget = GetIntermediateRenderTarget(resources, mode); using (var ds = renderTarget.CreateDrawingSession()) { DrawSourceGraphic(resources, ds, 0); } var pixels = renderTarget.SizeInPixels; resources.AddMessage("RenderTarget (dpi: {0}, size: {1}, pixels: {2},{3}) ->\n", renderTarget.Dpi, renderTarget.Size, pixels.Width, pixels.Height); return renderTarget; } }
CanvasBitmap GetSourceBitmap(PerDeviceResources resources) { CanvasBitmap bitmap; switch (CurrentSource) { case SourceMode.DefaultDpiBitmap: bitmap = resources.DefaultDpiBitmap; break; case SourceMode.HighDpiBitmap: bitmap = resources.HighDpiBitmap; break; case SourceMode.LowDpiBitmap: bitmap = resources.LowDpiBitmap; break; default: bitmap = null; break; } if (bitmap != null) { resources.AddMessage("Bitmap (dpi: {0}, size: {1}, pixels: {2}) ->\n", bitmap.Dpi, bitmap.Size, bitmap.SizeInPixels); } return bitmap; }