in WindowsSmartInk/SmartInkLaboratory/MainPage.xaml.cs [142:176]
private async Task PlaceIconAsync(string tag, double probability, Rect boundingBox)
{
if (probability < 0.4) {
foreach (var stroke in _sessionStrokes)
_allStrokes.Add(stroke);
}
else
{
var icon = await GetIconFileAsync(tag);
if (icon == null)
return;
var bytes = await FileIO.ReadBufferAsync(icon);
var ms = new InMemoryRandomAccessStream();
var dw = new Windows.Storage.Streams.DataWriter(ms);
dw.WriteBuffer(bytes);
await dw.StoreAsync();
ms.Seek(0);
var bm = new BitmapImage();
await bm.SetSourceAsync(ms);
var wb = new WriteableBitmap(bm.PixelWidth, bm.PixelHeight);
ms.Seek(0);
await wb.SetSourceAsync(ms);
var newBitmap = wb.Resize((int)boundingBox.Width, (int)boundingBox.Height, WriteableBitmapExtensions.Interpolation.Bilinear);
var image = new Image();
image.Source = newBitmap;
Canvas.SetTop(image, boundingBox.Top);
Canvas.SetLeft(image, boundingBox.Left);
iconCanvas.Children.Add(image);
}
}