in WindowsSmartInk/Microsoft.MTC.SmartInk/Extensions/InkStrokeCollectionExtensions.cs [60:105]
public static SoftwareBitmap DrawInk(this IList<InkStroke> strokes, double targetWidth = 0, double targetHeight = 0, float rotation = 0, Color? backgroundColor = null )
{
if (strokes == null)
throw new ArgumentNullException($"{nameof(strokes)} cannot be null");
var boundingBox = strokes.GetBoundingBox();
if (targetWidth == 0)
targetWidth = DEFAULT_WIDTH;
if (targetHeight == 0)
targetHeight = DEFAULT_HEIGHT;
if (backgroundColor == null)
backgroundColor = Colors.White;
var scale = CalculateScale(boundingBox, targetWidth, targetHeight);
var scaledStrokes = ScaleAndTransformStrokes(strokes, scale,rotation);
WriteableBitmap writeableBitmap = null;
CanvasDevice device = CanvasDevice.GetSharedDevice();
using (CanvasRenderTarget offscreen = new CanvasRenderTarget(device, (float) targetWidth, (float)targetHeight, 96))
{
using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
{
ds.Units = CanvasUnits.Pixels;
ds.Clear(backgroundColor.Value);
ds.DrawInk(scaledStrokes);
}
writeableBitmap = new WriteableBitmap((int)offscreen.SizeInPixels.Width, (int)offscreen.SizeInPixels.Height);
offscreen.GetPixelBytes().CopyTo(writeableBitmap.PixelBuffer);
}
SoftwareBitmap inkBitmap = SoftwareBitmap.CreateCopyFromBuffer(
writeableBitmap.PixelBuffer,
BitmapPixelFormat.Bgra8,
writeableBitmap.PixelWidth,
writeableBitmap.PixelHeight,
BitmapAlphaMode.Premultiplied
);
return inkBitmap;
}