public async Task <string> GetThumbnail(IRandomAccessStream stream, string filename, int width = 250, int height = 250) { byte[] thumbnailData = null; var success = false; while (!success) { try { thumbnailData = await _client.GetThumbnailAsync(stream.AsStream(), width, height); success = true; } catch (Exception ex) { // wait out the limitation in the API await Task.Delay(TimeSpan.FromSeconds(60)); } } var file = await(await AdventureObjectStorageHelper.GetDataSaveFolder()).CreateFileAsync(filename, CreationCollisionOption.GenerateUniqueName); using (var writeStream = await file.OpenAsync(FileAccessMode.ReadWrite)) { await writeStream.WriteAsync(thumbnailData.AsBuffer()); } return(file.Path); }
private async Task <MyData> LoadDummyData() { var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Data/data.json")); await file.CopyAsync(await AdventureObjectStorageHelper.GetDataSaveFolder(), _filename, NameCollisionOption.ReplaceExisting); var data = await _localStorageService.ReadFileAsync <MyData>(_filename); return(data); }
public async static Task <string> SaveInkToFile(this InkCanvas inker, string filename) { if (inker == null || inker.InkPresenter.StrokeContainer.GetStrokes().Count == 0) { return(null); } var file = await(await AdventureObjectStorageHelper.GetDataSaveFolder()).CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); if (file == null) { return(null); } using (var outputStream = await file.OpenAsync(FileAccessMode.ReadWrite)) { await inker.InkPresenter.StrokeContainer.SaveAsync(outputStream); } return(file.Path); }
public static async Task <string> RenderImageWithInkToFileAsync(InkCanvas inker, IRandomAccessStream imageStream, string filename) { if (inker.InkPresenter.StrokeContainer.GetStrokes().Count == 0) { return(null); } CanvasDevice device = CanvasDevice.GetSharedDevice(); CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, (int)inker.ActualWidth, (int)inker.ActualHeight, 96); var image = await CanvasBitmap.LoadAsync(device, imageStream); using (var ds = renderTarget.CreateDrawingSession()) { var imageBounds = image.GetBounds(device); var min = Math.Min(imageBounds.Height, imageBounds.Width); imageBounds.X = (imageBounds.Width - min) / 2; imageBounds.Y = (imageBounds.Height - min) / 2; imageBounds.Height = min; imageBounds.Width = min; ds.Clear(Colors.White); ds.DrawImage(image, new Rect(0, 0, inker.ActualWidth, inker.ActualWidth), imageBounds); ds.DrawInk(inker.InkPresenter.StrokeContainer.GetStrokes()); } var file = await(await AdventureObjectStorageHelper.GetDataSaveFolder()).CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite)) { await renderTarget.SaveAsync(stream, CanvasBitmapFileFormat.Jpeg, 1f); } return(file.Path); }