diff --git a/ShareX.HelpersLib/Printer/PrintHelper.cs b/ShareX.HelpersLib/Printer/PrintHelper.cs index ba7c2db6d..79ce9cfe5 100644 --- a/ShareX.HelpersLib/Printer/PrintHelper.cs +++ b/ShareX.HelpersLib/Printer/PrintHelper.cs @@ -158,7 +158,7 @@ private void PrintImage(PrintPageEventArgs e) Image img; if (Settings.AutoRotateImage && ((rect.Width > rect.Height && Image.Width < Image.Height) || - (rect.Width < rect.Height && Image.Width > Image.Height))) + (rect.Width < rect.Height && Image.Width > Image.Height))) { img = (Image)Image.Clone(); img.RotateFlip(RotateFlipType.Rotate90FlipNone); diff --git a/ShareX.MediaLib/Forms/ImageBeautifierForm.cs b/ShareX.MediaLib/Forms/ImageBeautifierForm.cs index 02b6fed1d..4add907c3 100644 --- a/ShareX.MediaLib/Forms/ImageBeautifierForm.cs +++ b/ShareX.MediaLib/Forms/ImageBeautifierForm.cs @@ -241,12 +241,12 @@ private void UpdateOptions() private void OnUploadImageRequested() { - UploadImageRequested?.Invoke(PreviewImage); + UploadImageRequested?.Invoke(PreviewImage.CloneSafe()); } private void OnPrintImageRequested() { - PrintImageRequested?.Invoke(PreviewImage); + PrintImageRequested?.Invoke(PreviewImage.CloneSafe()); } private async void ImageBeautifierForm_Shown(object sender, EventArgs e) diff --git a/ShareX/Forms/QRCodeForm.cs b/ShareX/Forms/QRCodeForm.cs index 8f6cbcf3c..061c99fd7 100644 --- a/ShareX/Forms/QRCodeForm.cs +++ b/ShareX/Forms/QRCodeForm.cs @@ -286,7 +286,7 @@ private void btnUploadImage_Click(object sender, EventArgs e) if (pbQRCode.Image != null) { Bitmap bmp = (Bitmap)pbQRCode.Image.Clone(); - UploadManager.UploadImage(bmp); + TaskHelpers.MainFormUploadImage(bmp); } } } diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index 29152e3e9..4b7bbfb4e 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -1040,33 +1040,9 @@ public static Bitmap AnnotateImage(Bitmap bmp, string filePath, TaskSettings tas return newFilePath; }; - form.CopyImageRequested += output => - { - Program.MainForm.InvokeSafe(() => - { - ClipboardHelpers.CopyImage(output); - }); - }; - - form.UploadImageRequested += output => - { - Program.MainForm.InvokeSafe(() => - { - UploadManager.UploadImage(output, taskSettings); - }); - }; - - form.PrintImageRequested += output => - { - Program.MainForm.InvokeSafe(() => - { - using (output) - { - PrintImage(output); - } - }); - }; - + form.CopyImageRequested += MainFormCopyImage; + form.UploadImageRequested += output => MainFormUploadImage(output, taskSettings); + form.PrintImageRequested += MainFormPrintImage; form.ShowDialog(); switch (form.Result) @@ -1088,6 +1064,33 @@ public static Bitmap AnnotateImage(Bitmap bmp, string filePath, TaskSettings tas return null; } + public static void MainFormCopyImage(Bitmap bmp) + { + Program.MainForm.InvokeSafe(() => + { + ClipboardHelpers.CopyImage(bmp); + }); + } + + public static void MainFormUploadImage(Bitmap bmp, TaskSettings taskSettings = null) + { + Program.MainForm.InvokeSafe(() => + { + UploadManager.UploadImage(bmp, taskSettings); + }); + } + + public static void MainFormPrintImage(Bitmap bmp) + { + Program.MainForm.InvokeSafe(() => + { + using (bmp) + { + PrintImage(bmp); + } + }); + } + public static void OpenImageBeautifier(TaskSettings taskSettings = null) { string filePath = ImageHelpers.OpenImageFileDialog(); @@ -1102,20 +1105,8 @@ public static void OpenImageBeautifier(string filePath, TaskSettings taskSetting if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); ImageBeautifierForm imageBeautifierForm = new ImageBeautifierForm(filePath, taskSettings.ToolsSettingsReference.ImageBeautifierOptions); - - imageBeautifierForm.UploadImageRequested += output => - { - UploadManager.UploadImage(output, taskSettings); - }; - - imageBeautifierForm.PrintImageRequested += output => - { - using (output) - { - PrintImage(output); - } - }; - + imageBeautifierForm.UploadImageRequested += output => MainFormUploadImage(output, taskSettings); + imageBeautifierForm.PrintImageRequested += MainFormPrintImage; imageBeautifierForm.Show(); } } @@ -1128,19 +1119,8 @@ public static Bitmap BeautifyImage(Bitmap bmp, TaskSettings taskSettings = null) using (ImageBeautifierForm imageBeautifierForm = new ImageBeautifierForm(bmp, taskSettings.ToolsSettingsReference.ImageBeautifierOptions)) { - imageBeautifierForm.UploadImageRequested += output => - { - UploadManager.UploadImage(output, taskSettings); - }; - - imageBeautifierForm.PrintImageRequested += output => - { - using (output) - { - PrintImage(output); - } - }; - + imageBeautifierForm.UploadImageRequested += output => MainFormUploadImage(output, taskSettings); + imageBeautifierForm.PrintImageRequested += MainFormPrintImage; imageBeautifierForm.ShowDialog(); return (Bitmap)imageBeautifierForm.PreviewImage.Clone();