Added more shadow options to image beautifier

This commit is contained in:
Jaex 2023-06-07 08:37:52 +03:00
parent 8e08f28620
commit fc2f5e7ca0
9 changed files with 293 additions and 36 deletions

View file

@ -1191,7 +1191,7 @@ public static Bitmap AddShadow(Bitmap bmp, float opacity, int size, float darkne
using (Graphics g = Graphics.FromImage(bmpResult)) using (Graphics g = Graphics.FromImage(bmpResult))
{ {
g.SetHighQuality(); g.SetHighQuality();
g.DrawImage(bmpShadow, -size + Math.Max(0, offset.X), -size + Math.Max(0, offset.Y), bmpShadow.Width, bmpShadow.Height); g.DrawImage(bmpShadow, -size + offset.X, -size + offset.Y, bmpShadow.Width, bmpShadow.Height);
g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height); g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);
} }
} }

View file

@ -46,6 +46,18 @@ private void InitializeComponent()
this.tlpMain = new System.Windows.Forms.TableLayoutPanel(); this.tlpMain = new System.Windows.Forms.TableLayoutPanel();
this.pbPreview = new ShareX.HelpersLib.MyPictureBox(); this.pbPreview = new ShareX.HelpersLib.MyPictureBox();
this.pOptions = new System.Windows.Forms.Panel(); this.pOptions = new System.Windows.Forms.Panel();
this.gbShadow = new System.Windows.Forms.GroupBox();
this.btnShadowExpand = new System.Windows.Forms.Button();
this.lblShadowAngleValue = new System.Windows.Forms.Label();
this.lblShadowDistanceValue = new System.Windows.Forms.Label();
this.lblShadowOpacityValue = new System.Windows.Forms.Label();
this.btnShadowColor = new ShareX.HelpersLib.ColorButton();
this.tbShadowAngle = new System.Windows.Forms.TrackBar();
this.lblShadowAngle = new System.Windows.Forms.Label();
this.tbShadowDistance = new System.Windows.Forms.TrackBar();
this.lblShadowOpacity = new System.Windows.Forms.Label();
this.lblShadowDistance = new System.Windows.Forms.Label();
this.tbShadowOpacity = new System.Windows.Forms.TrackBar();
this.btnResetOptions = new System.Windows.Forms.Button(); this.btnResetOptions = new System.Windows.Forms.Button();
this.lblBackgroundImageFilePath = new System.Windows.Forms.Label(); this.lblBackgroundImageFilePath = new System.Windows.Forms.Label();
this.btnBackgroundImageFilePathBrowse = new System.Windows.Forms.Button(); this.btnBackgroundImageFilePathBrowse = new System.Windows.Forms.Button();
@ -63,6 +75,10 @@ private void InitializeComponent()
((System.ComponentModel.ISupportInitialize)(this.tbShadowSize)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.tbShadowSize)).BeginInit();
this.tlpMain.SuspendLayout(); this.tlpMain.SuspendLayout();
this.pOptions.SuspendLayout(); this.pOptions.SuspendLayout();
this.gbShadow.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.tbShadowAngle)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.tbShadowDistance)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.tbShadowOpacity)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pbBackground)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pbBackground)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -147,20 +163,21 @@ private void InitializeComponent()
// lblShadowSize // lblShadowSize
// //
this.lblShadowSize.AutoSize = true; this.lblShadowSize.AutoSize = true;
this.lblShadowSize.Location = new System.Drawing.Point(13, 264); this.lblShadowSize.Location = new System.Drawing.Point(16, 32);
this.lblShadowSize.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 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(83, 17); this.lblShadowSize.Size = new System.Drawing.Size(34, 17);
this.lblShadowSize.TabIndex = 10; this.lblShadowSize.TabIndex = 10;
this.lblShadowSize.Text = "Shadow size:"; this.lblShadowSize.Text = "Size:";
// //
// tbShadowSize // tbShadowSize
// //
this.tbShadowSize.Location = new System.Drawing.Point(16, 288); this.tbShadowSize.AutoSize = false;
this.tbShadowSize.Location = new System.Drawing.Point(16, 56);
this.tbShadowSize.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); 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(296, 45); this.tbShadowSize.Size = new System.Drawing.Size(280, 32);
this.tbShadowSize.TabIndex = 11; 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);
@ -168,7 +185,7 @@ private void InitializeComponent()
// lblBackground // lblBackground
// //
this.lblBackground.AutoSize = true; this.lblBackground.AutoSize = true;
this.lblBackground.Location = new System.Drawing.Point(13, 336); this.lblBackground.Location = new System.Drawing.Point(13, 376);
this.lblBackground.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 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(80, 17); this.lblBackground.Size = new System.Drawing.Size(80, 17);
@ -207,7 +224,7 @@ private void InitializeComponent()
// //
// lblShadowSizeValue // lblShadowSizeValue
// //
this.lblShadowSizeValue.Location = new System.Drawing.Point(272, 264); this.lblShadowSizeValue.Location = new System.Drawing.Point(256, 32);
this.lblShadowSizeValue.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lblShadowSizeValue.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblShadowSizeValue.Name = "lblShadowSizeValue"; this.lblShadowSizeValue.Name = "lblShadowSizeValue";
this.lblShadowSizeValue.Size = new System.Drawing.Size(40, 24); this.lblShadowSizeValue.Size = new System.Drawing.Size(40, 24);
@ -247,6 +264,8 @@ private void InitializeComponent()
// //
// pOptions // pOptions
// //
this.pOptions.Controls.Add(this.btnShadowExpand);
this.pOptions.Controls.Add(this.gbShadow);
this.pOptions.Controls.Add(this.btnResetOptions); this.pOptions.Controls.Add(this.btnResetOptions);
this.pOptions.Controls.Add(this.lblBackgroundImageFilePath); this.pOptions.Controls.Add(this.lblBackgroundImageFilePath);
this.pOptions.Controls.Add(this.btnBackgroundImageFilePathBrowse); this.pOptions.Controls.Add(this.btnBackgroundImageFilePathBrowse);
@ -258,7 +277,6 @@ private void InitializeComponent()
this.pOptions.Controls.Add(this.btnCopy); this.pOptions.Controls.Add(this.btnCopy);
this.pOptions.Controls.Add(this.pbBackground); this.pOptions.Controls.Add(this.pbBackground);
this.pOptions.Controls.Add(this.lblMargin); this.pOptions.Controls.Add(this.lblMargin);
this.pOptions.Controls.Add(this.lblShadowSizeValue);
this.pOptions.Controls.Add(this.tbMargin); this.pOptions.Controls.Add(this.tbMargin);
this.pOptions.Controls.Add(this.lblRoundedCornerValue); this.pOptions.Controls.Add(this.lblRoundedCornerValue);
this.pOptions.Controls.Add(this.lblPadding); this.pOptions.Controls.Add(this.lblPadding);
@ -269,14 +287,147 @@ private void InitializeComponent()
this.pOptions.Controls.Add(this.lblRoundedCorner); this.pOptions.Controls.Add(this.lblRoundedCorner);
this.pOptions.Controls.Add(this.lblBackground); this.pOptions.Controls.Add(this.lblBackground);
this.pOptions.Controls.Add(this.tbRoundedCorner); this.pOptions.Controls.Add(this.tbRoundedCorner);
this.pOptions.Controls.Add(this.tbShadowSize);
this.pOptions.Controls.Add(this.lblShadowSize);
this.pOptions.Dock = System.Windows.Forms.DockStyle.Fill; this.pOptions.Dock = System.Windows.Forms.DockStyle.Fill;
this.pOptions.Location = new System.Drawing.Point(3, 3); this.pOptions.Location = new System.Drawing.Point(3, 3);
this.pOptions.Name = "pOptions"; this.pOptions.Name = "pOptions";
this.pOptions.Size = new System.Drawing.Size(329, 755); this.pOptions.Size = new System.Drawing.Size(329, 755);
this.pOptions.TabIndex = 0; this.pOptions.TabIndex = 0;
// //
// gbShadow
//
this.gbShadow.Controls.Add(this.lblShadowAngleValue);
this.gbShadow.Controls.Add(this.lblShadowDistanceValue);
this.gbShadow.Controls.Add(this.lblShadowOpacityValue);
this.gbShadow.Controls.Add(this.btnShadowColor);
this.gbShadow.Controls.Add(this.tbShadowSize);
this.gbShadow.Controls.Add(this.tbShadowAngle);
this.gbShadow.Controls.Add(this.lblShadowSizeValue);
this.gbShadow.Controls.Add(this.lblShadowAngle);
this.gbShadow.Controls.Add(this.lblShadowSize);
this.gbShadow.Controls.Add(this.tbShadowDistance);
this.gbShadow.Controls.Add(this.lblShadowOpacity);
this.gbShadow.Controls.Add(this.lblShadowDistance);
this.gbShadow.Controls.Add(this.tbShadowOpacity);
this.gbShadow.Location = new System.Drawing.Point(8, 264);
this.gbShadow.Name = "gbShadow";
this.gbShadow.Size = new System.Drawing.Size(312, 104);
this.gbShadow.TabIndex = 25;
this.gbShadow.TabStop = false;
this.gbShadow.Text = "Shadow";
//
// btnShadowExpand
//
this.btnShadowExpand.Image = global::ShareX.MediaLib.Properties.Resources.plus_white;
this.btnShadowExpand.Location = new System.Drawing.Point(280, 260);
this.btnShadowExpand.Name = "btnShadowExpand";
this.btnShadowExpand.Size = new System.Drawing.Size(30, 30);
this.btnShadowExpand.TabIndex = 16;
this.btnShadowExpand.Tag = "+";
this.btnShadowExpand.UseVisualStyleBackColor = true;
this.btnShadowExpand.Click += new System.EventHandler(this.btnShadowExpand_Click);
//
// lblShadowAngleValue
//
this.lblShadowAngleValue.Location = new System.Drawing.Point(256, 248);
this.lblShadowAngleValue.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblShadowAngleValue.Name = "lblShadowAngleValue";
this.lblShadowAngleValue.Size = new System.Drawing.Size(40, 24);
this.lblShadowAngleValue.TabIndex = 15;
this.lblShadowAngleValue.Text = "0";
this.lblShadowAngleValue.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// lblShadowDistanceValue
//
this.lblShadowDistanceValue.Location = new System.Drawing.Point(256, 176);
this.lblShadowDistanceValue.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblShadowDistanceValue.Name = "lblShadowDistanceValue";
this.lblShadowDistanceValue.Size = new System.Drawing.Size(40, 24);
this.lblShadowDistanceValue.TabIndex = 14;
this.lblShadowDistanceValue.Text = "0";
this.lblShadowDistanceValue.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// lblShadowOpacityValue
//
this.lblShadowOpacityValue.Location = new System.Drawing.Point(256, 104);
this.lblShadowOpacityValue.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblShadowOpacityValue.Name = "lblShadowOpacityValue";
this.lblShadowOpacityValue.Size = new System.Drawing.Size(40, 24);
this.lblShadowOpacityValue.TabIndex = 13;
this.lblShadowOpacityValue.Text = "0";
this.lblShadowOpacityValue.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// btnShadowColor
//
this.btnShadowColor.Color = System.Drawing.Color.Empty;
this.btnShadowColor.ColorPickerOptions = null;
this.btnShadowColor.Location = new System.Drawing.Point(16, 320);
this.btnShadowColor.Name = "btnShadowColor";
this.btnShadowColor.Size = new System.Drawing.Size(280, 32);
this.btnShadowColor.TabIndex = 6;
this.btnShadowColor.Text = "Color...";
this.btnShadowColor.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnShadowColor.UseVisualStyleBackColor = true;
this.btnShadowColor.ColorChanged += new ShareX.HelpersLib.ColorButton.ColorChangedEventHandler(this.btnShadowColor_ColorChanged);
//
// tbShadowAngle
//
this.tbShadowAngle.Location = new System.Drawing.Point(16, 272);
this.tbShadowAngle.Maximum = 180;
this.tbShadowAngle.Minimum = -180;
this.tbShadowAngle.Name = "tbShadowAngle";
this.tbShadowAngle.Size = new System.Drawing.Size(280, 45);
this.tbShadowAngle.TabIndex = 5;
this.tbShadowAngle.TickFrequency = 45;
this.tbShadowAngle.Scroll += new System.EventHandler(this.tbShadowAngle_Scroll);
//
// lblShadowAngle
//
this.lblShadowAngle.AutoSize = true;
this.lblShadowAngle.Location = new System.Drawing.Point(16, 248);
this.lblShadowAngle.Name = "lblShadowAngle";
this.lblShadowAngle.Size = new System.Drawing.Size(44, 17);
this.lblShadowAngle.TabIndex = 4;
this.lblShadowAngle.Text = "Angle:";
//
// tbShadowDistance
//
this.tbShadowDistance.Location = new System.Drawing.Point(16, 200);
this.tbShadowDistance.Maximum = 100;
this.tbShadowDistance.Name = "tbShadowDistance";
this.tbShadowDistance.Size = new System.Drawing.Size(280, 45);
this.tbShadowDistance.TabIndex = 3;
this.tbShadowDistance.TickFrequency = 10;
this.tbShadowDistance.Scroll += new System.EventHandler(this.tbShadowDistance_Scroll);
//
// lblShadowOpacity
//
this.lblShadowOpacity.AutoSize = true;
this.lblShadowOpacity.Location = new System.Drawing.Point(16, 104);
this.lblShadowOpacity.Name = "lblShadowOpacity";
this.lblShadowOpacity.Size = new System.Drawing.Size(55, 17);
this.lblShadowOpacity.TabIndex = 0;
this.lblShadowOpacity.Text = "Opacity:";
//
// lblShadowDistance
//
this.lblShadowDistance.AutoSize = true;
this.lblShadowDistance.Location = new System.Drawing.Point(16, 176);
this.lblShadowDistance.Name = "lblShadowDistance";
this.lblShadowDistance.Size = new System.Drawing.Size(60, 17);
this.lblShadowDistance.TabIndex = 2;
this.lblShadowDistance.Text = "Distance:";
//
// tbShadowOpacity
//
this.tbShadowOpacity.Location = new System.Drawing.Point(16, 128);
this.tbShadowOpacity.Maximum = 100;
this.tbShadowOpacity.Name = "tbShadowOpacity";
this.tbShadowOpacity.Size = new System.Drawing.Size(280, 45);
this.tbShadowOpacity.SmallChange = 10;
this.tbShadowOpacity.TabIndex = 1;
this.tbShadowOpacity.TickFrequency = 10;
this.tbShadowOpacity.Scroll += new System.EventHandler(this.tbShadowOpacity_Scroll);
//
// btnResetOptions // btnResetOptions
// //
this.btnResetOptions.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.btnResetOptions.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
@ -290,14 +441,14 @@ private void InitializeComponent()
// //
// lblBackgroundImageFilePath // lblBackgroundImageFilePath
// //
this.lblBackgroundImageFilePath.Location = new System.Drawing.Point(13, 432); this.lblBackgroundImageFilePath.Location = new System.Drawing.Point(13, 472);
this.lblBackgroundImageFilePath.Name = "lblBackgroundImageFilePath"; this.lblBackgroundImageFilePath.Name = "lblBackgroundImageFilePath";
this.lblBackgroundImageFilePath.Size = new System.Drawing.Size(296, 120); this.lblBackgroundImageFilePath.Size = new System.Drawing.Size(296, 120);
this.lblBackgroundImageFilePath.TabIndex = 22; this.lblBackgroundImageFilePath.TabIndex = 22;
// //
// btnBackgroundImageFilePathBrowse // btnBackgroundImageFilePathBrowse
// //
this.btnBackgroundImageFilePathBrowse.Location = new System.Drawing.Point(16, 392); this.btnBackgroundImageFilePathBrowse.Location = new System.Drawing.Point(16, 432);
this.btnBackgroundImageFilePathBrowse.Name = "btnBackgroundImageFilePathBrowse"; this.btnBackgroundImageFilePathBrowse.Name = "btnBackgroundImageFilePathBrowse";
this.btnBackgroundImageFilePathBrowse.Size = new System.Drawing.Size(296, 32); this.btnBackgroundImageFilePathBrowse.Size = new System.Drawing.Size(296, 32);
this.btnBackgroundImageFilePathBrowse.TabIndex = 21; this.btnBackgroundImageFilePathBrowse.TabIndex = 21;
@ -309,7 +460,7 @@ private void InitializeComponent()
// //
this.cbBackgroundType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cbBackgroundType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbBackgroundType.FormattingEnabled = true; this.cbBackgroundType.FormattingEnabled = true;
this.cbBackgroundType.Location = new System.Drawing.Point(16, 360); this.cbBackgroundType.Location = new System.Drawing.Point(16, 400);
this.cbBackgroundType.Name = "cbBackgroundType"; this.cbBackgroundType.Name = "cbBackgroundType";
this.cbBackgroundType.Size = new System.Drawing.Size(296, 25); this.cbBackgroundType.Size = new System.Drawing.Size(296, 25);
this.cbBackgroundType.TabIndex = 19; this.cbBackgroundType.TabIndex = 19;
@ -378,7 +529,7 @@ private void InitializeComponent()
// pbBackground // pbBackground
// //
this.pbBackground.Cursor = System.Windows.Forms.Cursors.Hand; this.pbBackground.Cursor = System.Windows.Forms.Cursors.Hand;
this.pbBackground.Location = new System.Drawing.Point(16, 392); this.pbBackground.Location = new System.Drawing.Point(16, 432);
this.pbBackground.Name = "pbBackground"; this.pbBackground.Name = "pbBackground";
this.pbBackground.Size = new System.Drawing.Size(296, 40); this.pbBackground.Size = new System.Drawing.Size(296, 40);
this.pbBackground.TabIndex = 14; this.pbBackground.TabIndex = 14;
@ -406,6 +557,11 @@ private void InitializeComponent()
this.tlpMain.ResumeLayout(false); this.tlpMain.ResumeLayout(false);
this.pOptions.ResumeLayout(false); this.pOptions.ResumeLayout(false);
this.pOptions.PerformLayout(); this.pOptions.PerformLayout();
this.gbShadow.ResumeLayout(false);
this.gbShadow.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.tbShadowAngle)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.tbShadowDistance)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.tbShadowOpacity)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pbBackground)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pbBackground)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -440,5 +596,17 @@ private void InitializeComponent()
private System.Windows.Forms.Button btnBackgroundImageFilePathBrowse; private System.Windows.Forms.Button btnBackgroundImageFilePathBrowse;
private System.Windows.Forms.Label lblBackgroundImageFilePath; private System.Windows.Forms.Label lblBackgroundImageFilePath;
private System.Windows.Forms.Button btnResetOptions; private System.Windows.Forms.Button btnResetOptions;
private System.Windows.Forms.TrackBar tbShadowOpacity;
private System.Windows.Forms.Label lblShadowOpacity;
private HelpersLib.ColorButton btnShadowColor;
private System.Windows.Forms.TrackBar tbShadowAngle;
private System.Windows.Forms.Label lblShadowAngle;
private System.Windows.Forms.TrackBar tbShadowDistance;
private System.Windows.Forms.Label lblShadowDistance;
private System.Windows.Forms.GroupBox gbShadow;
private System.Windows.Forms.Label lblShadowAngleValue;
private System.Windows.Forms.Label lblShadowDistanceValue;
private System.Windows.Forms.Label lblShadowOpacityValue;
private System.Windows.Forms.Button btnShadowExpand;
} }
} }

View file

@ -62,6 +62,17 @@ private ImageBeautifierForm(ImageBeautifierOptions options = null)
LoadOptions(); LoadOptions();
} }
public ImageBeautifierForm(Bitmap sourceImage, ImageBeautifierOptions options = null) : this(options)
{
SourceImage = sourceImage;
}
public ImageBeautifierForm(string filePath, ImageBeautifierOptions options = null) : this(options)
{
FilePath = filePath;
SourceImage = ImageHelpers.LoadImage(filePath);
}
private void LoadOptions() private void LoadOptions()
{ {
isReady = false; isReady = false;
@ -71,6 +82,10 @@ private void LoadOptions()
cbSmartPadding.Checked = Options.SmartPadding; cbSmartPadding.Checked = Options.SmartPadding;
tbRoundedCorner.SetValue(Options.RoundedCorner); tbRoundedCorner.SetValue(Options.RoundedCorner);
tbShadowSize.SetValue(Options.ShadowSize); tbShadowSize.SetValue(Options.ShadowSize);
tbShadowOpacity.SetValue(Options.ShadowOpacity);
tbShadowDistance.SetValue(Options.ShadowDistance);
tbShadowAngle.SetValue(Options.ShadowAngle);
btnShadowColor.Color = Options.ShadowColor;
if (cbBackgroundType.Items.Count == 0) if (cbBackgroundType.Items.Count == 0)
{ {
cbBackgroundType.Items.AddRange(Helpers.GetLocalizedEnumDescriptions<ImageBeautifierBackgroundType>()); cbBackgroundType.Items.AddRange(Helpers.GetLocalizedEnumDescriptions<ImageBeautifierBackgroundType>());
@ -83,23 +98,15 @@ private void LoadOptions()
isReady = true; isReady = true;
} }
public ImageBeautifierForm(Bitmap sourceImage, ImageBeautifierOptions options = null) : this(options)
{
SourceImage = sourceImage;
}
public ImageBeautifierForm(string filePath, ImageBeautifierOptions options = null) : this(options)
{
FilePath = filePath;
SourceImage = ImageHelpers.LoadImage(filePath);
}
private void UpdateUI() private void UpdateUI()
{ {
lblMarginValue.Text = tbMargin.Value.ToString(); lblMarginValue.Text = tbMargin.Value.ToString();
lblPaddingValue.Text = tbPadding.Value.ToString(); lblPaddingValue.Text = tbPadding.Value.ToString();
lblRoundedCornerValue.Text = tbRoundedCorner.Value.ToString(); lblRoundedCornerValue.Text = tbRoundedCorner.Value.ToString();
lblShadowSizeValue.Text = tbShadowSize.Value.ToString(); lblShadowSizeValue.Text = tbShadowSize.Value.ToString();
lblShadowOpacityValue.Text = tbShadowOpacity.Value.ToString();
lblShadowDistanceValue.Text = tbShadowDistance.Value.ToString();
lblShadowAngleValue.Text = tbShadowAngle.Value.ToString();
lblBackgroundImageFilePath.Text = Options.BackgroundImageFilePath; lblBackgroundImageFilePath.Text = Options.BackgroundImageFilePath;
} }
@ -199,6 +206,10 @@ private void UpdateOptions()
Options.SmartPadding = cbSmartPadding.Checked; Options.SmartPadding = cbSmartPadding.Checked;
Options.RoundedCorner = tbRoundedCorner.Value; Options.RoundedCorner = tbRoundedCorner.Value;
Options.ShadowSize = tbShadowSize.Value; Options.ShadowSize = tbShadowSize.Value;
Options.ShadowOpacity = tbShadowOpacity.Value;
Options.ShadowDistance = tbShadowDistance.Value;
Options.ShadowAngle = tbShadowAngle.Value;
Options.ShadowColor = btnShadowColor.Color;
} }
private void OnUploadImageRequested() private void OnUploadImageRequested()
@ -251,11 +262,47 @@ private async void tbRoundedCorner_MouseUp(object sender, MouseEventArgs e)
await UpdatePreview(); await UpdatePreview();
} }
private void btnShadowExpand_Click(object sender, EventArgs e)
{
if (btnShadowExpand.Tag is "+")
{
gbShadow.Size = new Size(gbShadow.Width, 368);
btnShadowExpand.Image = Resources.minus_white;
btnShadowExpand.Tag = "-";
}
else
{
gbShadow.Size = new Size(gbShadow.Width, 104);
btnShadowExpand.Image = Resources.plus_white;
btnShadowExpand.Tag = "+";
}
}
private async void tbShadowSize_Scroll(object sender, EventArgs e) private async void tbShadowSize_Scroll(object sender, EventArgs e)
{ {
await UpdatePreview(); await UpdatePreview();
} }
private async void tbShadowOpacity_Scroll(object sender, EventArgs e)
{
await UpdatePreview();
}
private async void tbShadowDistance_Scroll(object sender, EventArgs e)
{
await UpdatePreview();
}
private async void tbShadowAngle_Scroll(object sender, EventArgs e)
{
await UpdatePreview();
}
private async void btnShadowColor_ColorChanged(Color color)
{
await UpdatePreview();
}
private async void cbBackgroundType_SelectedIndexChanged(object sender, EventArgs e) private async void cbBackgroundType_SelectedIndexChanged(object sender, EventArgs e)
{ {
Options.BackgroundType = (ImageBeautifierBackgroundType)cbBackgroundType.SelectedIndex; Options.BackgroundType = (ImageBeautifierBackgroundType)cbBackgroundType.SelectedIndex;

View file

@ -38,6 +38,10 @@ public class ImageBeautifierOptions
public bool SmartPadding { get; set; } public bool SmartPadding { get; set; }
public int RoundedCorner { get; set; } public int RoundedCorner { get; set; }
public int ShadowSize { get; set; } public int ShadowSize { get; set; }
public int ShadowOpacity { get; set; }
public int ShadowDistance { get; set; }
public int ShadowAngle { get; set; }
public Color ShadowColor { get; set; }
public ImageBeautifierBackgroundType BackgroundType { get; set; } public ImageBeautifierBackgroundType BackgroundType { get; set; }
public GradientInfo BackgroundGradient { get; set; } public GradientInfo BackgroundGradient { get; set; }
public Color BackgroundColor { get; set; } public Color BackgroundColor { get; set; }
@ -55,6 +59,10 @@ public void ResetOptions()
SmartPadding = true; SmartPadding = true;
RoundedCorner = 20; RoundedCorner = 20;
ShadowSize = 30; ShadowSize = 30;
ShadowOpacity = 100;
ShadowDistance = 0;
ShadowAngle = -90;
ShadowColor = Color.Black;
BackgroundType = ImageBeautifierBackgroundType.Gradient; BackgroundType = ImageBeautifierBackgroundType.Gradient;
BackgroundGradient = new GradientInfo(LinearGradientMode.ForwardDiagonal, Color.FromArgb(255, 81, 47), Color.FromArgb(221, 36, 118)); BackgroundGradient = new GradientInfo(LinearGradientMode.ForwardDiagonal, Color.FromArgb(255, 81, 47), Color.FromArgb(221, 36, 118));
BackgroundColor = Color.FromArgb(34, 34, 34); BackgroundColor = Color.FromArgb(34, 34, 34);
@ -89,9 +97,11 @@ public Bitmap Render(Bitmap image)
resultImage = resultImageNew; resultImage = resultImageNew;
} }
if (ShadowSize > 0) if (ShadowOpacity > 0 && (ShadowSize > 0 || ShadowDistance > 0))
{ {
resultImage = ImageHelpers.AddShadow(resultImage, 1f, ShadowSize, 0f, Color.Black, new Point(0, 0), false); float shadowOpacity = ShadowOpacity / 100f;
Point shadowOffset = (Point)MathHelpers.DegreeToVector2(ShadowAngle, ShadowDistance);
resultImage = ImageHelpers.AddShadow(resultImage, shadowOpacity, ShadowSize, 0f, ShadowColor, shadowOffset, false);
} }
switch (BackgroundType) switch (BackgroundType)

View file

@ -180,6 +180,26 @@ internal class Resources {
} }
} }
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap minus_white {
get {
object obj = ResourceManager.GetObject("minus-white", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap plus_white {
get {
object obj = ResourceManager.GetObject("plus-white", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary> /// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap. /// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary> /// </summary>

View file

@ -139,12 +139,18 @@
<data name="AlignmentBottom" xml:space="preserve"> <data name="AlignmentBottom" xml:space="preserve">
<value>Bottom</value> <value>Bottom</value>
</data> </data>
<data name="WouldYouLikeToResetOptions" xml:space="preserve">
<value>Would you like to reset options?</value>
</data>
<data name="AlignmentRight" xml:space="preserve"> <data name="AlignmentRight" xml:space="preserve">
<value>Right</value> <value>Right</value>
</data> </data>
<data name="StartEncoding" xml:space="preserve"> <data name="StartEncoding" xml:space="preserve">
<value>Start encoding</value> <value>Start encoding</value>
</data> </data>
<data name="plus-white" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\plus-white.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="FFmpegError" xml:space="preserve"> <data name="FFmpegError" xml:space="preserve">
<value>FFmpeg error</value> <value>FFmpeg error</value>
</data> </data>
@ -157,25 +163,25 @@
<data name="VideoThumbnailerForm_btnBrowse_Click_Browse_for_media_file" xml:space="preserve"> <data name="VideoThumbnailerForm_btnBrowse_Click_Browse_for_media_file" xml:space="preserve">
<value>Browse for media file</value> <value>Browse for media file</value>
</data> </data>
<data name="printer" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\printer.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="AlignmentLeft" xml:space="preserve"> <data name="AlignmentLeft" xml:space="preserve">
<value>Left</value> <value>Left</value>
</data> </data>
<data name="AlignmentHorizontalCenter" xml:space="preserve"> <data name="AlignmentHorizontalCenter" xml:space="preserve">
<value>Center</value> <value>Center</value>
</data> </data>
<data name="Confirmation" xml:space="preserve">
<value>Confirmation</value>
</data>
<data name="LowerQualitySize" xml:space="preserve"> <data name="LowerQualitySize" xml:space="preserve">
<value>Lower quality/size</value> <value>Lower quality/size</value>
</data> </data>
<data name="disk-black" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="disk-black" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\disk-black.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\disk-black.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="printer" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="minus-white" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\printer.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\minus-white.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Confirmation" xml:space="preserve">
<value>Confirmation</value>
</data>
<data name="WouldYouLikeToResetOptions" xml:space="preserve">
<value>Would you like to reset options?</value>
</data> </data>
</root> </root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 648 B

View file

@ -451,6 +451,12 @@
<ItemGroup> <ItemGroup>
<None Include="Resources\printer.png" /> <None Include="Resources\printer.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="Resources\plus-white.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\minus-white.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.