private async System.Threading.Tasks.Task CopyToClipboardAsBitmapAsync() { if (_rSession != null) { string fileName = Path.GetTempFileName(); using (IRSessionEvaluation eval = await _rSession.BeginEvaluationAsync()) { await eval.ExportToBitmap("bmp", fileName, _lastPixelWidth, _lastPixelHeight); VsAppShell.Current.DispatchOnUIThread( () => { try { // Use Begin/EndInit to avoid locking the file on disk var image = new BitmapImage(); image.BeginInit(); image.UriSource = new Uri(fileName); image.CacheOption = BitmapCacheOption.OnLoad; image.EndInit(); Clipboard.SetImage(image); SafeFileDelete(fileName); } catch (Exception e) when(!e.IsCriticalException()) { MessageBox.Show(string.Format(Resources.PlotCopyToClipboardError, e.Message)); } }); } } }
private async System.Threading.Tasks.Task ExportAsImageAsync(string fileName, string deviceName) { if (_rSession != null) { using (IRSessionEvaluation eval = await _rSession.BeginEvaluationAsync()) { await eval.ExportToBitmap(deviceName, fileName, _lastPixelWidth, _lastPixelHeight); } } }