mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
ImageBeautifierForm improvements
This commit is contained in:
parent
e4f55a474a
commit
b9814e23bf
2 changed files with 189 additions and 86 deletions
130
ShareX.MediaLib/Forms/ImageBeautifierForm.Designer.cs
generated
130
ShareX.MediaLib/Forms/ImageBeautifierForm.Designer.cs
generated
|
@ -40,6 +40,10 @@ private void InitializeComponent()
|
||||||
this.lblBackground = new System.Windows.Forms.Label();
|
this.lblBackground = new System.Windows.Forms.Label();
|
||||||
this.pbPreview = new System.Windows.Forms.PictureBox();
|
this.pbPreview = new System.Windows.Forms.PictureBox();
|
||||||
this.pPreview = new System.Windows.Forms.Panel();
|
this.pPreview = new System.Windows.Forms.Panel();
|
||||||
|
this.lblMarginValue = new System.Windows.Forms.Label();
|
||||||
|
this.lblPaddingValue = new System.Windows.Forms.Label();
|
||||||
|
this.lblRoundedCornerValue = new System.Windows.Forms.Label();
|
||||||
|
this.lblShadowSizeValue = new System.Windows.Forms.Label();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.tbMargin)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.tbMargin)).BeginInit();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.tbPadding)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.tbPadding)).BeginInit();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.tbRoundedCorner)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.tbRoundedCorner)).BeginInit();
|
||||||
|
@ -51,18 +55,20 @@ private void InitializeComponent()
|
||||||
// lblMargin
|
// lblMargin
|
||||||
//
|
//
|
||||||
this.lblMargin.AutoSize = true;
|
this.lblMargin.AutoSize = true;
|
||||||
this.lblMargin.Location = new System.Drawing.Point(13, 16);
|
this.lblMargin.Location = new System.Drawing.Point(16, 16);
|
||||||
|
this.lblMargin.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
this.lblMargin.Name = "lblMargin";
|
this.lblMargin.Name = "lblMargin";
|
||||||
this.lblMargin.Size = new System.Drawing.Size(42, 13);
|
this.lblMargin.Size = new System.Drawing.Size(53, 17);
|
||||||
this.lblMargin.TabIndex = 0;
|
this.lblMargin.TabIndex = 0;
|
||||||
this.lblMargin.Text = "Margin:";
|
this.lblMargin.Text = "Margin:";
|
||||||
//
|
//
|
||||||
// tbMargin
|
// tbMargin
|
||||||
//
|
//
|
||||||
this.tbMargin.Location = new System.Drawing.Point(16, 40);
|
this.tbMargin.Location = new System.Drawing.Point(16, 40);
|
||||||
|
this.tbMargin.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.tbMargin.Maximum = 300;
|
this.tbMargin.Maximum = 300;
|
||||||
this.tbMargin.Name = "tbMargin";
|
this.tbMargin.Name = "tbMargin";
|
||||||
this.tbMargin.Size = new System.Drawing.Size(256, 45);
|
this.tbMargin.Size = new System.Drawing.Size(299, 45);
|
||||||
this.tbMargin.TabIndex = 1;
|
this.tbMargin.TabIndex = 1;
|
||||||
this.tbMargin.TickFrequency = 10;
|
this.tbMargin.TickFrequency = 10;
|
||||||
this.tbMargin.Scroll += new System.EventHandler(this.tbMargin_Scroll);
|
this.tbMargin.Scroll += new System.EventHandler(this.tbMargin_Scroll);
|
||||||
|
@ -70,29 +76,32 @@ private void InitializeComponent()
|
||||||
// lblPadding
|
// lblPadding
|
||||||
//
|
//
|
||||||
this.lblPadding.AutoSize = true;
|
this.lblPadding.AutoSize = true;
|
||||||
this.lblPadding.Location = new System.Drawing.Point(13, 96);
|
this.lblPadding.Location = new System.Drawing.Point(16, 88);
|
||||||
|
this.lblPadding.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
this.lblPadding.Name = "lblPadding";
|
this.lblPadding.Name = "lblPadding";
|
||||||
this.lblPadding.Size = new System.Drawing.Size(49, 13);
|
this.lblPadding.Size = new System.Drawing.Size(59, 17);
|
||||||
this.lblPadding.TabIndex = 2;
|
this.lblPadding.TabIndex = 3;
|
||||||
this.lblPadding.Text = "Padding:";
|
this.lblPadding.Text = "Padding:";
|
||||||
//
|
//
|
||||||
// tbPadding
|
// tbPadding
|
||||||
//
|
//
|
||||||
this.tbPadding.Location = new System.Drawing.Point(16, 120);
|
this.tbPadding.Location = new System.Drawing.Point(16, 112);
|
||||||
|
this.tbPadding.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.tbPadding.Maximum = 200;
|
this.tbPadding.Maximum = 200;
|
||||||
this.tbPadding.Name = "tbPadding";
|
this.tbPadding.Name = "tbPadding";
|
||||||
this.tbPadding.Size = new System.Drawing.Size(256, 45);
|
this.tbPadding.Size = new System.Drawing.Size(299, 45);
|
||||||
this.tbPadding.TabIndex = 3;
|
this.tbPadding.TabIndex = 4;
|
||||||
this.tbPadding.TickFrequency = 10;
|
this.tbPadding.TickFrequency = 10;
|
||||||
this.tbPadding.Scroll += new System.EventHandler(this.tbPadding_Scroll);
|
this.tbPadding.Scroll += new System.EventHandler(this.tbPadding_Scroll);
|
||||||
//
|
//
|
||||||
// cbSmartPadding
|
// cbSmartPadding
|
||||||
//
|
//
|
||||||
this.cbSmartPadding.AutoSize = true;
|
this.cbSmartPadding.AutoSize = true;
|
||||||
this.cbSmartPadding.Location = new System.Drawing.Point(16, 168);
|
this.cbSmartPadding.Location = new System.Drawing.Point(16, 160);
|
||||||
|
this.cbSmartPadding.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.cbSmartPadding.Name = "cbSmartPadding";
|
this.cbSmartPadding.Name = "cbSmartPadding";
|
||||||
this.cbSmartPadding.Size = new System.Drawing.Size(94, 17);
|
this.cbSmartPadding.Size = new System.Drawing.Size(114, 21);
|
||||||
this.cbSmartPadding.TabIndex = 4;
|
this.cbSmartPadding.TabIndex = 6;
|
||||||
this.cbSmartPadding.Text = "Smart padding";
|
this.cbSmartPadding.Text = "Smart padding";
|
||||||
this.cbSmartPadding.UseVisualStyleBackColor = true;
|
this.cbSmartPadding.UseVisualStyleBackColor = true;
|
||||||
this.cbSmartPadding.CheckedChanged += new System.EventHandler(this.cbSmartPadding_CheckedChanged);
|
this.cbSmartPadding.CheckedChanged += new System.EventHandler(this.cbSmartPadding_CheckedChanged);
|
||||||
|
@ -100,48 +109,53 @@ private void InitializeComponent()
|
||||||
// lblRoundedCorner
|
// lblRoundedCorner
|
||||||
//
|
//
|
||||||
this.lblRoundedCorner.AutoSize = true;
|
this.lblRoundedCorner.AutoSize = true;
|
||||||
this.lblRoundedCorner.Location = new System.Drawing.Point(13, 200);
|
this.lblRoundedCorner.Location = new System.Drawing.Point(16, 192);
|
||||||
|
this.lblRoundedCorner.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
this.lblRoundedCorner.Name = "lblRoundedCorner";
|
this.lblRoundedCorner.Name = "lblRoundedCorner";
|
||||||
this.lblRoundedCorner.Size = new System.Drawing.Size(87, 13);
|
this.lblRoundedCorner.Size = new System.Drawing.Size(106, 17);
|
||||||
this.lblRoundedCorner.TabIndex = 5;
|
this.lblRoundedCorner.TabIndex = 7;
|
||||||
this.lblRoundedCorner.Text = "Rounded corner:";
|
this.lblRoundedCorner.Text = "Rounded corner:";
|
||||||
//
|
//
|
||||||
// tbRoundedCorner
|
// tbRoundedCorner
|
||||||
//
|
//
|
||||||
this.tbRoundedCorner.Location = new System.Drawing.Point(16, 224);
|
this.tbRoundedCorner.Location = new System.Drawing.Point(16, 216);
|
||||||
|
this.tbRoundedCorner.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.tbRoundedCorner.Maximum = 50;
|
this.tbRoundedCorner.Maximum = 50;
|
||||||
this.tbRoundedCorner.Name = "tbRoundedCorner";
|
this.tbRoundedCorner.Name = "tbRoundedCorner";
|
||||||
this.tbRoundedCorner.Size = new System.Drawing.Size(256, 45);
|
this.tbRoundedCorner.Size = new System.Drawing.Size(299, 45);
|
||||||
this.tbRoundedCorner.TabIndex = 6;
|
this.tbRoundedCorner.TabIndex = 8;
|
||||||
this.tbRoundedCorner.TickFrequency = 5;
|
this.tbRoundedCorner.TickFrequency = 5;
|
||||||
this.tbRoundedCorner.Scroll += new System.EventHandler(this.tbRoundedCorner_Scroll);
|
this.tbRoundedCorner.Scroll += new System.EventHandler(this.tbRoundedCorner_Scroll);
|
||||||
//
|
//
|
||||||
// lblShadowSize
|
// lblShadowSize
|
||||||
//
|
//
|
||||||
this.lblShadowSize.AutoSize = true;
|
this.lblShadowSize.AutoSize = true;
|
||||||
this.lblShadowSize.Location = new System.Drawing.Point(13, 280);
|
this.lblShadowSize.Location = new System.Drawing.Point(16, 264);
|
||||||
|
this.lblShadowSize.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
this.lblShadowSize.Name = "lblShadowSize";
|
this.lblShadowSize.Name = "lblShadowSize";
|
||||||
this.lblShadowSize.Size = new System.Drawing.Size(70, 13);
|
this.lblShadowSize.Size = new System.Drawing.Size(83, 17);
|
||||||
this.lblShadowSize.TabIndex = 7;
|
this.lblShadowSize.TabIndex = 10;
|
||||||
this.lblShadowSize.Text = "Shadow size:";
|
this.lblShadowSize.Text = "Shadow size:";
|
||||||
//
|
//
|
||||||
// tbShadowSize
|
// tbShadowSize
|
||||||
//
|
//
|
||||||
this.tbShadowSize.Location = new System.Drawing.Point(16, 304);
|
this.tbShadowSize.Location = new System.Drawing.Point(16, 288);
|
||||||
|
this.tbShadowSize.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.tbShadowSize.Maximum = 100;
|
this.tbShadowSize.Maximum = 100;
|
||||||
this.tbShadowSize.Name = "tbShadowSize";
|
this.tbShadowSize.Name = "tbShadowSize";
|
||||||
this.tbShadowSize.Size = new System.Drawing.Size(256, 45);
|
this.tbShadowSize.Size = new System.Drawing.Size(299, 45);
|
||||||
this.tbShadowSize.TabIndex = 8;
|
this.tbShadowSize.TabIndex = 11;
|
||||||
this.tbShadowSize.TickFrequency = 5;
|
this.tbShadowSize.TickFrequency = 5;
|
||||||
this.tbShadowSize.Scroll += new System.EventHandler(this.tbShadowSize_Scroll);
|
this.tbShadowSize.Scroll += new System.EventHandler(this.tbShadowSize_Scroll);
|
||||||
//
|
//
|
||||||
// lblBackground
|
// lblBackground
|
||||||
//
|
//
|
||||||
this.lblBackground.AutoSize = true;
|
this.lblBackground.AutoSize = true;
|
||||||
this.lblBackground.Location = new System.Drawing.Point(13, 360);
|
this.lblBackground.Location = new System.Drawing.Point(16, 336);
|
||||||
|
this.lblBackground.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
this.lblBackground.Name = "lblBackground";
|
this.lblBackground.Name = "lblBackground";
|
||||||
this.lblBackground.Size = new System.Drawing.Size(68, 13);
|
this.lblBackground.Size = new System.Drawing.Size(80, 17);
|
||||||
this.lblBackground.TabIndex = 9;
|
this.lblBackground.TabIndex = 13;
|
||||||
this.lblBackground.Text = "Background:";
|
this.lblBackground.Text = "Background:";
|
||||||
//
|
//
|
||||||
// pbPreview
|
// pbPreview
|
||||||
|
@ -161,16 +175,61 @@ private void InitializeComponent()
|
||||||
this.pPreview.AutoScroll = true;
|
this.pPreview.AutoScroll = true;
|
||||||
this.pPreview.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
this.pPreview.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
this.pPreview.Controls.Add(this.pbPreview);
|
this.pPreview.Controls.Add(this.pbPreview);
|
||||||
this.pPreview.Location = new System.Drawing.Point(288, 8);
|
this.pPreview.Location = new System.Drawing.Point(328, 8);
|
||||||
|
this.pPreview.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.pPreview.Name = "pPreview";
|
this.pPreview.Name = "pPreview";
|
||||||
this.pPreview.Size = new System.Drawing.Size(504, 432);
|
this.pPreview.Size = new System.Drawing.Size(1048, 745);
|
||||||
this.pPreview.TabIndex = 10;
|
this.pPreview.TabIndex = 14;
|
||||||
|
//
|
||||||
|
// lblMarginValue
|
||||||
|
//
|
||||||
|
this.lblMarginValue.Location = new System.Drawing.Point(272, 16);
|
||||||
|
this.lblMarginValue.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.lblMarginValue.Name = "lblMarginValue";
|
||||||
|
this.lblMarginValue.Size = new System.Drawing.Size(40, 24);
|
||||||
|
this.lblMarginValue.TabIndex = 2;
|
||||||
|
this.lblMarginValue.Text = "0";
|
||||||
|
this.lblMarginValue.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
|
||||||
|
//
|
||||||
|
// lblPaddingValue
|
||||||
|
//
|
||||||
|
this.lblPaddingValue.Location = new System.Drawing.Point(272, 88);
|
||||||
|
this.lblPaddingValue.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.lblPaddingValue.Name = "lblPaddingValue";
|
||||||
|
this.lblPaddingValue.Size = new System.Drawing.Size(40, 24);
|
||||||
|
this.lblPaddingValue.TabIndex = 5;
|
||||||
|
this.lblPaddingValue.Text = "0";
|
||||||
|
this.lblPaddingValue.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
|
||||||
|
//
|
||||||
|
// lblRoundedCornerValue
|
||||||
|
//
|
||||||
|
this.lblRoundedCornerValue.Location = new System.Drawing.Point(272, 192);
|
||||||
|
this.lblRoundedCornerValue.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.lblRoundedCornerValue.Name = "lblRoundedCornerValue";
|
||||||
|
this.lblRoundedCornerValue.Size = new System.Drawing.Size(40, 24);
|
||||||
|
this.lblRoundedCornerValue.TabIndex = 9;
|
||||||
|
this.lblRoundedCornerValue.Text = "0";
|
||||||
|
this.lblRoundedCornerValue.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
|
||||||
|
//
|
||||||
|
// lblShadowSizeValue
|
||||||
|
//
|
||||||
|
this.lblShadowSizeValue.Location = new System.Drawing.Point(272, 264);
|
||||||
|
this.lblShadowSizeValue.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.lblShadowSizeValue.Name = "lblShadowSizeValue";
|
||||||
|
this.lblShadowSizeValue.Size = new System.Drawing.Size(40, 24);
|
||||||
|
this.lblShadowSizeValue.TabIndex = 12;
|
||||||
|
this.lblShadowSizeValue.Text = "0";
|
||||||
|
this.lblShadowSizeValue.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
|
||||||
//
|
//
|
||||||
// ImageBeautifierForm
|
// ImageBeautifierForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 447);
|
this.ClientSize = new System.Drawing.Size(1384, 761);
|
||||||
|
this.Controls.Add(this.lblShadowSizeValue);
|
||||||
|
this.Controls.Add(this.lblRoundedCornerValue);
|
||||||
|
this.Controls.Add(this.lblPaddingValue);
|
||||||
|
this.Controls.Add(this.lblMarginValue);
|
||||||
this.Controls.Add(this.pPreview);
|
this.Controls.Add(this.pPreview);
|
||||||
this.Controls.Add(this.lblBackground);
|
this.Controls.Add(this.lblBackground);
|
||||||
this.Controls.Add(this.tbShadowSize);
|
this.Controls.Add(this.tbShadowSize);
|
||||||
|
@ -182,10 +241,13 @@ private void InitializeComponent()
|
||||||
this.Controls.Add(this.lblPadding);
|
this.Controls.Add(this.lblPadding);
|
||||||
this.Controls.Add(this.tbMargin);
|
this.Controls.Add(this.tbMargin);
|
||||||
this.Controls.Add(this.lblMargin);
|
this.Controls.Add(this.lblMargin);
|
||||||
|
this.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
this.Name = "ImageBeautifierForm";
|
this.Name = "ImageBeautifierForm";
|
||||||
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "ShareX - Image beautifier";
|
this.Text = "ShareX - Image beautifier";
|
||||||
|
this.Shown += new System.EventHandler(this.ImageBeautifierForm_Shown);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.tbMargin)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.tbMargin)).EndInit();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.tbPadding)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.tbPadding)).EndInit();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.tbRoundedCorner)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.tbRoundedCorner)).EndInit();
|
||||||
|
@ -211,5 +273,9 @@ private void InitializeComponent()
|
||||||
private System.Windows.Forms.Label lblBackground;
|
private System.Windows.Forms.Label lblBackground;
|
||||||
private System.Windows.Forms.PictureBox pbPreview;
|
private System.Windows.Forms.PictureBox pbPreview;
|
||||||
private System.Windows.Forms.Panel pPreview;
|
private System.Windows.Forms.Panel pPreview;
|
||||||
|
private System.Windows.Forms.Label lblMarginValue;
|
||||||
|
private System.Windows.Forms.Label lblPaddingValue;
|
||||||
|
private System.Windows.Forms.Label lblRoundedCornerValue;
|
||||||
|
private System.Windows.Forms.Label lblShadowSizeValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,7 +24,9 @@ You should have received a copy of the GNU General Public License
|
||||||
#endregion License Information (GPL v3)
|
#endregion License Information (GPL v3)
|
||||||
|
|
||||||
using ShareX.HelpersLib;
|
using ShareX.HelpersLib;
|
||||||
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ShareX.MediaLib
|
namespace ShareX.MediaLib
|
||||||
|
@ -35,7 +37,7 @@ public partial class ImageBeautifierForm : Form
|
||||||
public Bitmap PreviewImage { get; private set; }
|
public Bitmap PreviewImage { get; private set; }
|
||||||
public ImageBeautifierOptions Options { get; private set; }
|
public ImageBeautifierOptions Options { get; private set; }
|
||||||
|
|
||||||
private bool isReady;
|
private bool isReady, isBusy, isPending;
|
||||||
|
|
||||||
public ImageBeautifierForm(Bitmap sourceImage, ImageBeautifierOptions options = null)
|
public ImageBeautifierForm(Bitmap sourceImage, ImageBeautifierOptions options = null)
|
||||||
{
|
{
|
||||||
|
@ -50,71 +52,101 @@ public ImageBeautifierForm(Bitmap sourceImage, ImageBeautifierOptions options =
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ShareXResources.ApplyTheme(this);
|
ShareXResources.ApplyTheme(this);
|
||||||
|
|
||||||
Size = new Size(1400, 800);
|
|
||||||
tbMargin.SetValue(Options.Margin);
|
tbMargin.SetValue(Options.Margin);
|
||||||
tbPadding.SetValue(Options.Padding);
|
tbPadding.SetValue(Options.Padding);
|
||||||
cbSmartPadding.Checked = Options.SmartPadding;
|
cbSmartPadding.Checked = Options.SmartPadding;
|
||||||
tbRoundedCorner.SetValue(Options.RoundedCorner);
|
tbRoundedCorner.SetValue(Options.RoundedCorner);
|
||||||
tbShadowSize.SetValue(Options.ShadowSize);
|
tbShadowSize.SetValue(Options.ShadowSize);
|
||||||
|
UpdateUI();
|
||||||
|
|
||||||
isReady = true;
|
isReady = true;
|
||||||
|
|
||||||
UpdatePreview();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdatePreview()
|
private void UpdateUI()
|
||||||
|
{
|
||||||
|
lblMarginValue.Text = tbMargin.Value.ToString();
|
||||||
|
lblPaddingValue.Text = tbPadding.Value.ToString();
|
||||||
|
lblRoundedCornerValue.Text = tbRoundedCorner.Value.ToString();
|
||||||
|
lblShadowSizeValue.Text = tbShadowSize.Value.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task UpdatePreview()
|
||||||
{
|
{
|
||||||
if (isReady)
|
if (isReady)
|
||||||
{
|
{
|
||||||
UpdateOptions();
|
UpdateUI();
|
||||||
Bitmap resultImage = RenderPreview(SourceImage, Options);
|
|
||||||
PreviewImage?.Dispose();
|
if (isBusy)
|
||||||
PreviewImage = resultImage;
|
{
|
||||||
pbPreview.Image = PreviewImage;
|
isPending = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isBusy = true;
|
||||||
|
|
||||||
|
UpdateOptions();
|
||||||
|
|
||||||
|
Bitmap resultImage = await RenderPreview(SourceImage, Options);
|
||||||
|
PreviewImage?.Dispose();
|
||||||
|
PreviewImage = resultImage;
|
||||||
|
pbPreview.Image = PreviewImage;
|
||||||
|
|
||||||
|
isBusy = false;
|
||||||
|
|
||||||
|
if (isPending)
|
||||||
|
{
|
||||||
|
isPending = false;
|
||||||
|
|
||||||
|
await UpdatePreview();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bitmap RenderPreview(Bitmap sourceImage, ImageBeautifierOptions options)
|
private static async Task<Bitmap> RenderPreview(Bitmap sourceImage, ImageBeautifierOptions options)
|
||||||
{
|
{
|
||||||
Bitmap resultImage = (Bitmap)sourceImage.Clone();
|
return await Task.Run(() =>
|
||||||
|
|
||||||
if (options.SmartPadding)
|
|
||||||
{
|
{
|
||||||
resultImage = ImageHelpers.AutoCropImage(resultImage, true, AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right, options.Padding);
|
Bitmap resultImage = (Bitmap)sourceImage.Clone();
|
||||||
}
|
|
||||||
else if (options.Padding > 0)
|
|
||||||
{
|
|
||||||
Color color = resultImage.GetPixel(0, 0);
|
|
||||||
Bitmap resultImageNew = ImageHelpers.AddCanvas(resultImage, options.Padding, color);
|
|
||||||
resultImage.Dispose();
|
|
||||||
resultImage = resultImageNew;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.RoundedCorner > 0)
|
if (options.SmartPadding)
|
||||||
{
|
{
|
||||||
resultImage = ImageHelpers.RoundedCorners(resultImage, options.RoundedCorner);
|
resultImage = ImageHelpers.AutoCropImage(resultImage, true, AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right, options.Padding);
|
||||||
}
|
}
|
||||||
|
else if (options.Padding > 0)
|
||||||
|
{
|
||||||
|
Color color = resultImage.GetPixel(0, 0);
|
||||||
|
Bitmap resultImageNew = ImageHelpers.AddCanvas(resultImage, options.Padding, color);
|
||||||
|
resultImage.Dispose();
|
||||||
|
resultImage = resultImageNew;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.Margin > 0)
|
if (options.RoundedCorner > 0)
|
||||||
{
|
{
|
||||||
Bitmap resultImageNew = ImageHelpers.AddCanvas(resultImage, options.Margin);
|
resultImage = ImageHelpers.RoundedCorners(resultImage, options.RoundedCorner);
|
||||||
resultImage.Dispose();
|
}
|
||||||
resultImage = resultImageNew;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.ShadowSize > 0)
|
if (options.Margin > 0)
|
||||||
{
|
{
|
||||||
resultImage = ImageHelpers.AddShadow(resultImage, 1f, options.ShadowSize, 0f, Color.Black, new Point(0, 0), false);
|
Bitmap resultImageNew = ImageHelpers.AddCanvas(resultImage, options.Margin);
|
||||||
}
|
resultImage.Dispose();
|
||||||
|
resultImage = resultImageNew;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.Background != null)
|
if (options.ShadowSize > 0)
|
||||||
{
|
{
|
||||||
Bitmap resultImageNew = ImageHelpers.FillBackground(resultImage, options.Background);
|
resultImage = ImageHelpers.AddShadow(resultImage, 1f, options.ShadowSize, 0f, Color.Black, new Point(0, 0), false);
|
||||||
resultImage.Dispose();
|
}
|
||||||
resultImage = resultImageNew;
|
|
||||||
}
|
|
||||||
|
|
||||||
return resultImage;
|
if (options.Background != null)
|
||||||
|
{
|
||||||
|
Bitmap resultImageNew = ImageHelpers.FillBackground(resultImage, options.Background);
|
||||||
|
resultImage.Dispose();
|
||||||
|
resultImage = resultImageNew;
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultImage;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateOptions()
|
private void UpdateOptions()
|
||||||
|
@ -126,29 +158,34 @@ private void UpdateOptions()
|
||||||
Options.ShadowSize = tbShadowSize.Value;
|
Options.ShadowSize = tbShadowSize.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tbMargin_Scroll(object sender, System.EventArgs e)
|
private async void ImageBeautifierForm_Shown(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
UpdatePreview();
|
await UpdatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tbPadding_Scroll(object sender, System.EventArgs e)
|
private async void tbMargin_Scroll(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
UpdatePreview();
|
await UpdatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cbSmartPadding_CheckedChanged(object sender, System.EventArgs e)
|
private async void tbPadding_Scroll(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
UpdatePreview();
|
await UpdatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tbRoundedCorner_Scroll(object sender, System.EventArgs e)
|
private async void cbSmartPadding_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
UpdatePreview();
|
await UpdatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tbShadowSize_Scroll(object sender, System.EventArgs e)
|
private async void tbRoundedCorner_Scroll(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
UpdatePreview();
|
await UpdatePreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void tbShadowSize_Scroll(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await UpdatePreview();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue