ImageBeautifierForm improvements

This commit is contained in:
Jaex 2023-04-24 23:50:36 +03:00
parent 2ec6429270
commit 34fcbc6fb1
2 changed files with 42 additions and 4 deletions

View file

@ -38,6 +38,9 @@ public partial class ImageBeautifierForm : Form
public ImageBeautifierOptions Options { get; private set; } public ImageBeautifierOptions Options { get; private set; }
public string FilePath { get; private set; } public string FilePath { get; private set; }
public event Action<Bitmap> UploadImageRequested;
public event Action<Bitmap> PrintImageRequested;
private bool isReady, isBusy, isPending; private bool isReady, isBusy, isPending;
private ImageBeautifierForm(ImageBeautifierOptions options = null) private ImageBeautifierForm(ImageBeautifierOptions options = null)
@ -176,6 +179,16 @@ private void UpdateOptions()
Options.ShadowSize = tbShadowSize.Value; Options.ShadowSize = tbShadowSize.Value;
} }
private void OnUploadImageRequested()
{
UploadImageRequested?.Invoke(PreviewImage);
}
private void OnPrintImageRequested()
{
PrintImageRequested?.Invoke(PreviewImage);
}
private async void ImageBeautifierForm_Shown(object sender, EventArgs e) private async void ImageBeautifierForm_Shown(object sender, EventArgs e)
{ {
await UpdatePreview(); await UpdatePreview();
@ -232,12 +245,18 @@ private void btnSaveAs_Click(object sender, EventArgs e)
private void btnUpload_Click(object sender, EventArgs e) private void btnUpload_Click(object sender, EventArgs e)
{ {
if (PreviewImage != null)
{
OnUploadImageRequested();
}
} }
private void btnPrint_Click(object sender, EventArgs e) private void btnPrint_Click(object sender, EventArgs e)
{ {
if (PreviewImage != null)
{
OnPrintImageRequested();
}
} }
private async void tbShadowSize_Scroll(object sender, EventArgs e) private async void tbShadowSize_Scroll(object sender, EventArgs e)

View file

@ -1037,7 +1037,10 @@ public static Bitmap AnnotateImage(Bitmap bmp, string filePath, TaskSettings tas
{ {
Program.MainForm.InvokeSafe(() => Program.MainForm.InvokeSafe(() =>
{ {
using (output) { PrintImage(output); } using (output)
{
PrintImage(output);
}
}); });
}; };
@ -1062,13 +1065,29 @@ public static Bitmap AnnotateImage(Bitmap bmp, string filePath, TaskSettings tas
return null; return null;
} }
public static void OpenImageBeautifier() public static void OpenImageBeautifier(TaskSettings taskSettings = null)
{ {
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
string filePath = ImageHelpers.OpenImageFileDialog(); string filePath = ImageHelpers.OpenImageFileDialog();
if (!string.IsNullOrEmpty(filePath)) if (!string.IsNullOrEmpty(filePath))
{ {
ImageBeautifierForm imageBeautifierForm = new ImageBeautifierForm(filePath, new ImageBeautifierOptions()); ImageBeautifierForm imageBeautifierForm = new ImageBeautifierForm(filePath, new ImageBeautifierOptions());
imageBeautifierForm.UploadImageRequested += output =>
{
UploadManager.UploadImage(output, taskSettings);
};
imageBeautifierForm.PrintImageRequested += output =>
{
using (output)
{
PrintImage(output);
}
};
imageBeautifierForm.Show(); imageBeautifierForm.Show();
} }
} }