ImageBeautifierForm improvements

This commit is contained in:
Jaex 2023-04-24 23:14:38 +03:00
parent b7bb8d7fe0
commit 2ec6429270
11 changed files with 359 additions and 133 deletions

View file

@ -43,9 +43,14 @@ private void InitializeComponent()
this.lblRoundedCornerValue = new System.Windows.Forms.Label();
this.lblShadowSizeValue = new System.Windows.Forms.Label();
this.tlpMain = new System.Windows.Forms.TableLayoutPanel();
this.pOptions = new System.Windows.Forms.Panel();
this.pbBackground = new System.Windows.Forms.PictureBox();
this.pbPreview = new ShareX.HelpersLib.MyPictureBox();
this.pOptions = new System.Windows.Forms.Panel();
this.btnPrint = new System.Windows.Forms.Button();
this.btnSave = new System.Windows.Forms.Button();
this.btnUpload = new System.Windows.Forms.Button();
this.btnSaveAs = new System.Windows.Forms.Button();
this.btnCopy = new System.Windows.Forms.Button();
this.pbBackground = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.tbMargin)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.tbPadding)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.tbRoundedCorner)).BeginInit();
@ -216,8 +221,28 @@ private void InitializeComponent()
this.tlpMain.Size = new System.Drawing.Size(1384, 761);
this.tlpMain.TabIndex = 15;
//
// pbPreview
//
this.pbPreview.BackColor = System.Drawing.SystemColors.Window;
this.pbPreview.Dock = System.Windows.Forms.DockStyle.Fill;
this.pbPreview.DrawCheckeredBackground = true;
this.pbPreview.EnableRightClickMenu = true;
this.pbPreview.FullscreenOnClick = true;
this.pbPreview.Location = new System.Drawing.Point(335, 0);
this.pbPreview.Margin = new System.Windows.Forms.Padding(0);
this.pbPreview.Name = "pbPreview";
this.pbPreview.PictureBoxBackColor = System.Drawing.SystemColors.Window;
this.pbPreview.ShowImageSizeLabel = true;
this.pbPreview.Size = new System.Drawing.Size(1049, 761);
this.pbPreview.TabIndex = 12;
//
// pOptions
//
this.pOptions.Controls.Add(this.btnPrint);
this.pOptions.Controls.Add(this.btnSave);
this.pOptions.Controls.Add(this.btnUpload);
this.pOptions.Controls.Add(this.btnSaveAs);
this.pOptions.Controls.Add(this.btnCopy);
this.pOptions.Controls.Add(this.pbBackground);
this.pOptions.Controls.Add(this.lblMargin);
this.pOptions.Controls.Add(this.lblShadowSizeValue);
@ -239,6 +264,60 @@ private void InitializeComponent()
this.pOptions.Size = new System.Drawing.Size(329, 755);
this.pOptions.TabIndex = 0;
//
// btnPrint
//
this.btnPrint.Image = global::ShareX.MediaLib.Properties.Resources.printer;
this.btnPrint.Location = new System.Drawing.Point(264, 696);
this.btnPrint.Name = "btnPrint";
this.btnPrint.Size = new System.Drawing.Size(56, 48);
this.btnPrint.TabIndex = 19;
this.btnPrint.UseVisualStyleBackColor = true;
this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
//
// btnSave
//
this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnSave.Image = global::ShareX.MediaLib.Properties.Resources.disk_black;
this.btnSave.Location = new System.Drawing.Point(72, 696);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(56, 48);
this.btnSave.TabIndex = 18;
this.btnSave.UseVisualStyleBackColor = true;
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
//
// btnUpload
//
this.btnUpload.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnUpload.Image = global::ShareX.MediaLib.Properties.Resources.upload_cloud;
this.btnUpload.Location = new System.Drawing.Point(200, 696);
this.btnUpload.Name = "btnUpload";
this.btnUpload.Size = new System.Drawing.Size(56, 48);
this.btnUpload.TabIndex = 17;
this.btnUpload.UseVisualStyleBackColor = true;
this.btnUpload.Click += new System.EventHandler(this.btnUpload_Click);
//
// btnSaveAs
//
this.btnSaveAs.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnSaveAs.Image = global::ShareX.MediaLib.Properties.Resources.disks_black;
this.btnSaveAs.Location = new System.Drawing.Point(136, 696);
this.btnSaveAs.Name = "btnSaveAs";
this.btnSaveAs.Size = new System.Drawing.Size(56, 48);
this.btnSaveAs.TabIndex = 16;
this.btnSaveAs.UseVisualStyleBackColor = true;
this.btnSaveAs.Click += new System.EventHandler(this.btnSaveAs_Click);
//
// btnCopy
//
this.btnCopy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnCopy.Image = global::ShareX.MediaLib.Properties.Resources.document_copy;
this.btnCopy.Location = new System.Drawing.Point(8, 696);
this.btnCopy.Name = "btnCopy";
this.btnCopy.Size = new System.Drawing.Size(56, 48);
this.btnCopy.TabIndex = 15;
this.btnCopy.UseVisualStyleBackColor = true;
this.btnCopy.Click += new System.EventHandler(this.btnCopy_Click);
//
// pbBackground
//
this.pbBackground.Cursor = System.Windows.Forms.Cursors.Hand;
@ -249,18 +328,6 @@ private void InitializeComponent()
this.pbBackground.TabStop = false;
this.pbBackground.Click += new System.EventHandler(this.pbBackground_Click);
//
// pbPreview
//
this.pbPreview.BackColor = System.Drawing.SystemColors.Window;
this.pbPreview.Dock = System.Windows.Forms.DockStyle.Fill;
this.pbPreview.DrawCheckeredBackground = true;
this.pbPreview.Location = new System.Drawing.Point(335, 0);
this.pbPreview.Margin = new System.Windows.Forms.Padding(0);
this.pbPreview.Name = "pbPreview";
this.pbPreview.PictureBoxBackColor = System.Drawing.SystemColors.Window;
this.pbPreview.Size = new System.Drawing.Size(1049, 761);
this.pbPreview.TabIndex = 12;
//
// ImageBeautifierForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
@ -269,6 +336,7 @@ private void InitializeComponent()
this.Controls.Add(this.tlpMain);
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.MinimumSize = new System.Drawing.Size(1000, 600);
this.Name = "ImageBeautifierForm";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
@ -305,5 +373,10 @@ private void InitializeComponent()
private System.Windows.Forms.Panel pOptions;
private HelpersLib.MyPictureBox pbPreview;
private System.Windows.Forms.PictureBox pbBackground;
private System.Windows.Forms.Button btnSave;
private System.Windows.Forms.Button btnUpload;
private System.Windows.Forms.Button btnSaveAs;
private System.Windows.Forms.Button btnCopy;
private System.Windows.Forms.Button btnPrint;
}
}

View file

@ -36,12 +36,12 @@ public partial class ImageBeautifierForm : Form
public Bitmap SourceImage { get; private set; }
public Bitmap PreviewImage { get; private set; }
public ImageBeautifierOptions Options { get; private set; }
public string FilePath { get; private set; }
private bool isReady, isBusy, isPending;
public ImageBeautifierForm(Bitmap sourceImage, ImageBeautifierOptions options = null)
private ImageBeautifierForm(ImageBeautifierOptions options = null)
{
SourceImage = sourceImage;
Options = options;
if (Options == null)
@ -63,6 +63,17 @@ public ImageBeautifierForm(Bitmap sourceImage, ImageBeautifierOptions options =
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()
{
lblMarginValue.Text = tbMargin.Value.ToString();
@ -190,6 +201,45 @@ private async void tbRoundedCorner_Scroll(object sender, EventArgs e)
await UpdatePreview();
}
private void btnCopy_Click(object sender, EventArgs e)
{
if (PreviewImage != null)
{
ClipboardHelpers.CopyImage(PreviewImage);
}
}
private void btnSave_Click(object sender, EventArgs e)
{
if (PreviewImage != null && !string.IsNullOrEmpty(FilePath))
{
ImageHelpers.SaveImage(PreviewImage, FilePath);
}
}
private void btnSaveAs_Click(object sender, EventArgs e)
{
if (PreviewImage != null)
{
string filePath = ImageHelpers.SaveImageFileDialog(PreviewImage, FilePath);
if (!string.IsNullOrEmpty(filePath))
{
FilePath = filePath;
}
}
}
private void btnUpload_Click(object sender, EventArgs e)
{
}
private void btnPrint_Click(object sender, EventArgs e)
{
}
private async void tbShadowSize_Scroll(object sender, EventArgs e)
{
await UpdatePreview();

View file

@ -19,7 +19,7 @@ namespace ShareX.MediaLib.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
@ -114,6 +114,36 @@ internal static string AlignmentVerticalCenter {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap disk_black {
get {
object obj = ResourceManager.GetObject("disk-black", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap disks_black {
get {
object obj = ResourceManager.GetObject("disks-black", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap document_copy {
get {
object obj = ResourceManager.GetObject("document-copy", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized string similar to FFmpeg error.
/// </summary>
@ -141,6 +171,16 @@ internal static string LowerQualitySize {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap printer {
get {
object obj = ResourceManager.GetObject("printer", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized string similar to Start encoding.
/// </summary>
@ -168,6 +208,16 @@ internal static string ThumbnailsSuccessfullyGenerated {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap upload_cloud {
get {
object obj = ResourceManager.GetObject("upload-cloud", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized string similar to Browse for media file.
/// </summary>

View file

@ -3,7 +3,7 @@
<!--
Microsoft ResX Schema
Version 1.3
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
@ -14,16 +14,17 @@
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
@ -45,7 +46,7 @@
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
@ -58,20 +59,38 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
@ -90,28 +109,38 @@
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="VideoThumbnailerForm_btnBrowse_Click_Browse_for_media_file" xml:space="preserve">
<value>Browse for media file</value>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="document-copy" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\document-copy.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ThumbnailsSuccessfullyGenerated" xml:space="preserve">
<value>Thumbnails successfully generated.</value>
</data>
<data name="LowerQualitySize" xml:space="preserve">
<value>Lower quality/size</value>
<data name="disks-black" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\disks-black.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="AlignmentTop" xml:space="preserve">
<value>Top</value>
</data>
<data name="StopEncoding" xml:space="preserve">
<value>Stop encoding</value>
</data>
<data name="HigherQualitySize" xml:space="preserve">
<value>Higher quality/size</value>
</data>
<data name="StopEncoding" xml:space="preserve">
<value>Stop encoding</value>
<data name="AlignmentBottom" xml:space="preserve">
<value>Bottom</value>
</data>
<data name="AlignmentRight" xml:space="preserve">
<value>Right</value>
</data>
<data name="StartEncoding" xml:space="preserve">
<value>Start encoding</value>
@ -119,22 +148,28 @@
<data name="FFmpegError" xml:space="preserve">
<value>FFmpeg error</value>
</data>
<data name="AlignmentTop" xml:space="preserve">
<value>Top</value>
</data>
<data name="AlignmentHorizontalCenter" xml:space="preserve">
<data name="AlignmentVerticalCenter" xml:space="preserve">
<value>Center</value>
</data>
<data name="AlignmentBottom" xml:space="preserve">
<value>Bottom</value>
<data name="upload-cloud" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\upload-cloud.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="VideoThumbnailerForm_btnBrowse_Click_Browse_for_media_file" xml:space="preserve">
<value>Browse for media file</value>
</data>
<data name="AlignmentLeft" xml:space="preserve">
<value>Left</value>
</data>
<data name="AlignmentVerticalCenter" xml:space="preserve">
<data name="AlignmentHorizontalCenter" xml:space="preserve">
<value>Center</value>
</data>
<data name="AlignmentRight" xml:space="preserve">
<value>Right</value>
<data name="LowerQualitySize" xml:space="preserve">
<value>Lower quality/size</value>
</data>
<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>
</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>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 722 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -436,6 +436,21 @@
<EmbeddedResource Include="Properties\Resources.zh-CN.resx" />
<EmbeddedResource Include="Properties\Resources.zh-TW.resx" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\document-copy.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\disk-black.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\disks-black.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\upload-cloud.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\printer.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.

View file

@ -1019,7 +1019,10 @@ public static Bitmap AnnotateImage(Bitmap bmp, string filePath, TaskSettings tas
form.CopyImageRequested += output =>
{
Program.MainForm.InvokeSafe(() => ClipboardHelpers.CopyImage(output));
Program.MainForm.InvokeSafe(() =>
{
ClipboardHelpers.CopyImage(output);
});
};
form.UploadImageRequested += output =>
@ -1061,11 +1064,11 @@ public static Bitmap AnnotateImage(Bitmap bmp, string filePath, TaskSettings tas
public static void OpenImageBeautifier()
{
Bitmap sourceImage = ImageHelpers.LoadImageWithFileDialog();
string filePath = ImageHelpers.OpenImageFileDialog();
if (sourceImage != null)
if (!string.IsNullOrEmpty(filePath))
{
ImageBeautifierForm imageBeautifierForm = new ImageBeautifierForm(sourceImage);
ImageBeautifierForm imageBeautifierForm = new ImageBeautifierForm(filePath, new ImageBeautifierOptions());
imageBeautifierForm.Show();
}
}