private void uploadImageFile(string filePath, bool edit = false) { // save unedited capture if (Properties.Settings.Default.saveImageAtAll && Directory.Exists(Properties.Settings.Default.SaveImagesHere)) { string name = DateTime.UtcNow.ToString("yyyyMMddHHmmssfff"); File.Copy(filePath, Properties.Settings.Default.SaveImagesHere + @"\" + name + ".png"); } if (edit) { imageEditor editor = new imageEditor(filePath); editor.ShowDialog(); filePath = System.IO.Path.GetTempPath() + "screenshot_edited.png"; } else { if (File.Exists(System.IO.Path.GetTempPath() + "screenshot_edited.png")) { File.Delete(System.IO.Path.GetTempPath() + "screenshot_edited.png"); } File.Copy(filePath, System.IO.Path.GetTempPath() + "screenshot_edited.png"); filePath = System.IO.Path.GetTempPath() + "screenshot_edited.png"; } if (File.Exists(System.IO.Path.GetTempPath() + "screenshot_edited.png")) { //string url = (string)cap.UploadImage(filePath); BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += cap.UploadImage; bw.RunWorkerCompleted += uploadImageFileCompleted; bw.RunWorkerAsync(filePath); } }
private void uploadImageFile(string filePath, bool edit = false) { string name = DateTime.UtcNow.ToString("yyyyMMddHHmmssfff"); // Will always be .png here. Weather to compress or not is decided in the editor. string whereToSave = Properties.Settings.Default.SaveImagesHere + @"\" + name + (filePath.EndsWith(".png") ? ".png" : ".jpg"); // save unedited capture if (Properties.Settings.Default.saveImageAtAll && Directory.Exists(Properties.Settings.Default.SaveImagesHere)) { //if (!edit) //{ File.Copy(filePath, whereToSave); //} } Image bitmapImage = Image.FromFile(filePath); //TODO: Add error checking for when windows clipboard stops working o.o try { Clipboard.SetImage(bitmapImage); } catch (System.Runtime.InteropServices.ExternalException e) { Console.WriteLine("Failed to copy to clipboard. is windows broken?, \n" + e.Message); } bitmapImage.Dispose(); string editedPath = System.IO.Path.GetTempPath() + "screenshot_edited.png"; if (edit) { imageEditor editor = new imageEditor(filePath, whereToSave); editor.ShowDialog(); if (editor.checkBox1.Checked)//If compressed, pick the compressed version. { editedPath = System.IO.Path.GetTempPath() + "screenshot_edited.jpg"; } filePath = editedPath; if (File.Exists(editedPath)) { bitmapImage = Image.FromFile(filePath); Clipboard.SetImage(bitmapImage); bitmapImage.Dispose(); } } else { if (File.Exists(editedPath)) { File.Delete(editedPath); } File.Copy(filePath, editedPath); filePath = editedPath; } if (!Properties.Settings.Default.NeverUpload) { if (File.Exists(editedPath)) { //string url = (string)cap.UploadImage(filePath); BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += cap.UploadImage; bw.RunWorkerCompleted += uploadImageFileCompleted; bw.RunWorkerAsync(filePath); } } }