public void BeginSaveImage(TileIndex id, BitmapSource image, Stream stream) { string imagePath = GetImagePath(id); bool errorWhileDeleting = false; bool containsOld = Contains(id); if (containsOld && saveOption == SaveOption.ForceUpdate) { try { File.Delete(imagePath); } catch (IOException exc) { // todo возможно, тут добавить файл в очередь на удаление или перезапись новым содержимым // когда он перестанет быть блокированным MapsTraceSource.Instance.ServerInformationTraceSource.TraceInformation("{0} - error while deleting tile {1}: {2}", ServerName, id, exc.Message); errorWhileDeleting = true; } } bool shouldSave = saveOption == SaveOption.ForceUpdate && !errorWhileDeleting || saveOption == SaveOption.PreserveOld && !containsOld; if (shouldSave) { MapsTraceSource.Instance.ServerInformationTraceSource.TraceInformation(string.Format("{0}: begin to save: id = {1}", ServerName, id)); FileMap[id] = true; Statistics.IntValues["ImagesSaved"]++; BitmapSource bmp = image; if (!bmp.IsFrozen) { } Task saveTask = Task.Factory.StartNew(() => { if (stream == null) { ScreenshotHelper.SaveBitmapToFile(bmp, imagePath); } else { ScreenshotHelper.SaveStreamToFile(stream, imagePath); } }).WithExceptionThrowingInDispatcher(Dispatcher); } }
private async void HighResScreenshotExecute(object target, ExecutedRoutedEventArgs e) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "PNG (*.png)|*.png|JPEG (*.jpg)|*.jpg|BMP (*.bmp)|*.bmp|GIF (*.gif)|*.gif"; dlg.FilterIndex = 1; dlg.AddExtension = true; if (dlg.ShowDialog().GetValueOrDefault(false)) { var bmp = await plotter2D.ExportHighResScreenshot(10000, 4000, 96); ScreenshotHelper.SaveBitmapToFile(bmp, dlg.FileName); e.Handled = true; } }
/// <summary>Saves screenshot to file.</summary> /// <param name="filePath">File path.</param> public async Task SaveScreenshot(string filePath) { ScreenshotHelper.Parameters parameters = (this is Plotter2D) ? ((Plotter2D)this).Viewport.ScreenshotParameters : new ScreenshotHelper.Parameters(); ScreenshotHelper.SaveBitmapToFile(await CreateScreenshot(), filePath, parameters.Dpi); }
/// <summary>Saves screenshot to file.</summary> /// <param name="filePath">File path.</param> public void SaveScreenshot(string filePath) { ScreenshotHelper.SaveBitmapToFile(CreateScreenshot(), filePath); }
public void SaveScreenshot(string filePath) { /// <summary>Saves screenshot to file.</summary> /// <param name="filePath">File path.</param> ScreenshotHelper.SaveBitmapToFile(CreateScreenshot(), filePath); }
public void BeginSaveImage(TileIndex id, BitmapSource image, Stream stream) { string imagePath = GetImagePath(id); bool errorWhileDeleting = false; bool containsOld = Contains(id); if (containsOld && saveOption == SaveOption.ForceUpdate) { try { File.Delete(imagePath); } catch (IOException exc) { // todo возможно, тут добавить файл в очередь на удаление или перезапись новым содержимым // когда он перестанет быть блокированным MapsTraceSource.Instance.ServerInformationTraceSource.TraceInformation("{0} - error while deleting tile {1}: {2}", ServerName, id, exc.Message); errorWhileDeleting = true; } } bool shouldSave = saveOption == SaveOption.ForceUpdate && !errorWhileDeleting || saveOption == SaveOption.PreserveOld && !containsOld; if (shouldSave) { MapsTraceSource.Instance.ServerInformationTraceSource.TraceInformation(String.Format("{0}: begin to save: id = {1}", ServerName, id)); FileMap[id] = true; Statistics.IntValues["ImagesSaved"]++; BitmapSource bmp = image; if (!bmp.IsFrozen) { } ThreadPool.QueueUserWorkItem(new WaitCallback((unused) => { // Try to write tile to cache. Conflicts are possible // especially in case of multiple Map control instances. // That's why exception is only dumped to debug output. try { if (stream == null) { ScreenshotHelper.SaveBitmapToFile(bmp, imagePath); } else { ScreenshotHelper.SaveStreamToFile(stream, imagePath); } } catch (Exception exc) { Debug.WriteLine(String.Format("Error writing tile to cache: {0}", exc.Message)); } })); } }