Added canvas size form

This commit is contained in:
Jaex 2017-10-21 23:43:39 +03:00
parent ec03407647
commit da2c9844da
7 changed files with 453 additions and 29 deletions

View file

@ -419,13 +419,16 @@ public static Bitmap QuickAutoCropImage(Bitmap bmp)
return bmp;
}
/// <summary>Adds empty space around image.</summary>
public static Image AddCanvas(Image img, Padding margin)
{
if (margin.All == 0 || img.Width + margin.Horizontal < 1 || img.Height + margin.Vertical < 1)
{
return null;
}
Bitmap bmp = img.CreateEmptyBitmap(margin.Horizontal, margin.Vertical);
using (Graphics g = Graphics.FromImage(bmp))
using (img)
{
g.SetHighQuality();
g.DrawImage(img, margin.Left, margin.Top, img.Width, img.Height);

View file

@ -32,23 +32,8 @@ namespace ShareX.ImageEffectsLib
{
internal class Canvas : ImageEffect
{
private Padding margin;
[DefaultValue(typeof(Padding), "0, 0, 0, 0")]
public Padding Margin
{
get
{
return margin;
}
set
{
if (value.Top >= 0 && value.Right >= 0 && value.Bottom >= 0 && value.Left >= 0)
{
margin = value;
}
}
}
public Padding Margin { get; set; }
public Canvas()
{
@ -57,9 +42,15 @@ public Canvas()
public override Image Apply(Image img)
{
if (Margin.All == 0) return img;
Image result = ImageHelpers.AddCanvas(img, Margin);
return ImageHelpers.AddCanvas(img, Margin);
if (result == null)
{
return img;
}
img.Dispose();
return result;
}
}
}

View file

@ -0,0 +1,220 @@
namespace ShareX.ScreenCaptureLib
{
partial class CanvasSizeForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.nudLeft = new System.Windows.Forms.NumericUpDown();
this.lblLeft = new System.Windows.Forms.Label();
this.lblRight = new System.Windows.Forms.Label();
this.nudRight = new System.Windows.Forms.NumericUpDown();
this.lblTop = new System.Windows.Forms.Label();
this.nudTop = new System.Windows.Forms.NumericUpDown();
this.lblBottom = new System.Windows.Forms.Label();
this.nudBottom = new System.Windows.Forms.NumericUpDown();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.nudLeft)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudRight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudTop)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudBottom)).BeginInit();
this.SuspendLayout();
//
// nudLeft
//
this.nudLeft.Location = new System.Drawing.Point(16, 80);
this.nudLeft.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.nudLeft.Minimum = new decimal(new int[] {
10000,
0,
0,
-2147483648});
this.nudLeft.Name = "nudLeft";
this.nudLeft.Size = new System.Drawing.Size(64, 20);
this.nudLeft.TabIndex = 0;
this.nudLeft.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// lblLeft
//
this.lblLeft.AutoSize = true;
this.lblLeft.Location = new System.Drawing.Point(13, 64);
this.lblLeft.Name = "lblLeft";
this.lblLeft.Size = new System.Drawing.Size(28, 13);
this.lblLeft.TabIndex = 1;
this.lblLeft.Text = "Left:";
//
// lblRight
//
this.lblRight.AutoSize = true;
this.lblRight.Location = new System.Drawing.Point(157, 64);
this.lblRight.Name = "lblRight";
this.lblRight.Size = new System.Drawing.Size(35, 13);
this.lblRight.TabIndex = 3;
this.lblRight.Text = "Right:";
//
// nudRight
//
this.nudRight.Location = new System.Drawing.Point(160, 80);
this.nudRight.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.nudRight.Minimum = new decimal(new int[] {
10000,
0,
0,
-2147483648});
this.nudRight.Name = "nudRight";
this.nudRight.Size = new System.Drawing.Size(64, 20);
this.nudRight.TabIndex = 2;
this.nudRight.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// lblTop
//
this.lblTop.AutoSize = true;
this.lblTop.Location = new System.Drawing.Point(85, 8);
this.lblTop.Name = "lblTop";
this.lblTop.Size = new System.Drawing.Size(29, 13);
this.lblTop.TabIndex = 5;
this.lblTop.Text = "Top:";
//
// nudTop
//
this.nudTop.Location = new System.Drawing.Point(88, 24);
this.nudTop.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.nudTop.Minimum = new decimal(new int[] {
10000,
0,
0,
-2147483648});
this.nudTop.Name = "nudTop";
this.nudTop.Size = new System.Drawing.Size(64, 20);
this.nudTop.TabIndex = 4;
this.nudTop.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// lblBottom
//
this.lblBottom.AutoSize = true;
this.lblBottom.Location = new System.Drawing.Point(85, 120);
this.lblBottom.Name = "lblBottom";
this.lblBottom.Size = new System.Drawing.Size(43, 13);
this.lblBottom.TabIndex = 7;
this.lblBottom.Text = "Bottom:";
//
// nudBottom
//
this.nudBottom.Location = new System.Drawing.Point(88, 136);
this.nudBottom.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.nudBottom.Minimum = new decimal(new int[] {
10000,
0,
0,
-2147483648});
this.nudBottom.Name = "nudBottom";
this.nudBottom.Size = new System.Drawing.Size(64, 20);
this.nudBottom.TabIndex = 6;
this.nudBottom.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(8, 176);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(108, 23);
this.btnOK.TabIndex = 8;
this.btnOK.Text = "OK";
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(124, 176);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(108, 23);
this.btnCancel.TabIndex = 9;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// CanvasSizeForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(240, 208);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.lblBottom);
this.Controls.Add(this.nudBottom);
this.Controls.Add(this.lblTop);
this.Controls.Add(this.nudTop);
this.Controls.Add(this.lblRight);
this.Controls.Add(this.nudRight);
this.Controls.Add(this.lblLeft);
this.Controls.Add(this.nudLeft);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CanvasSizeForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ShareX - Canvas size";
this.TopMost = true;
this.Shown += new System.EventHandler(this.CanvasSizeForm_Shown);
((System.ComponentModel.ISupportInitialize)(this.nudLeft)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudRight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudTop)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudBottom)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.NumericUpDown nudLeft;
private System.Windows.Forms.Label lblLeft;
private System.Windows.Forms.Label lblRight;
private System.Windows.Forms.NumericUpDown nudRight;
private System.Windows.Forms.Label lblTop;
private System.Windows.Forms.NumericUpDown nudTop;
private System.Windows.Forms.Label lblBottom;
private System.Windows.Forms.NumericUpDown nudBottom;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
}
}

View file

@ -0,0 +1,75 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2017 ShareX Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ShareX.ScreenCaptureLib
{
public partial class CanvasSizeForm : Form
{
public Padding Canvas { get; private set; }
public CanvasSizeForm()
{
InitializeComponent();
Icon = ShareXResources.Icon;
}
public CanvasSizeForm(Padding canvas) : this()
{
Canvas = canvas;
nudLeft.Value = canvas.Left;
nudTop.Value = canvas.Top;
nudRight.Value = canvas.Right;
nudBottom.Value = canvas.Bottom;
}
private void CanvasSizeForm_Shown(object sender, EventArgs e)
{
this.ForceActivate();
}
private void btnOK_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Canvas = new Padding((int)nudLeft.Value, (int)nudTop.Value, (int)nudRight.Value, (int)nudBottom.Value);
Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
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
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</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"><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">
<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">
<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
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: 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" 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">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -1347,19 +1347,25 @@ public Image CropImage(Rectangle rect, bool onlyIfSizeDifferent = false)
private void CanvasSize()
{
Padding padding = new Padding(100, 25, 50, 75);
Image img = ImageHelpers.AddCanvas(form.Image, padding);
if (img != null)
using (CanvasSizeForm canvasSizeForm = new CanvasSizeForm())
{
Rectangle oldRect = form.ImageRectangle;
if (canvasSizeForm.ShowDialog() == DialogResult.OK)
{
Padding canvas = canvasSizeForm.Canvas;
Image img = ImageHelpers.AddCanvas(form.Image, canvas);
form.InitBackground(img);
if (img != null)
{
Rectangle oldRect = form.ImageRectangle;
MoveAll(form.ImageRectangle.X - oldRect.X + padding.Left, form.ImageRectangle.Y - oldRect.Y + padding.Top);
RemoveOutsideShapes();
form.InitBackground(img);
isAnnotated = true;
MoveAll(form.ImageRectangle.X - oldRect.X + canvas.Left, form.ImageRectangle.Y - oldRect.Y + canvas.Top);
RemoveOutsideShapes();
isAnnotated = true;
}
}
}
}

View file

@ -81,6 +81,12 @@
<Compile Include="Animations\BaseAnimation.cs" />
<Compile Include="Animations\PointAnimation.cs" />
<Compile Include="Animations\RectangleAnimation.cs" />
<Compile Include="Forms\CanvasSizeForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\CanvasSizeForm.Designer.cs">
<DependentUpon>CanvasSizeForm.cs</DependentUpon>
</Compile>
<Compile Include="Shapes\AnnotationOptions.cs" />
<Compile Include="Enums.cs" />
<Compile Include="Forms\RegionCaptureSimpleAnnotateForm.cs">
@ -253,6 +259,9 @@
<None Include="Resources\exclamation-button.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Forms\CanvasSizeForm.resx">
<DependentUpon>CanvasSizeForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\FFmpegOptionsForm.it-IT.resx">
<DependentUpon>FFmpegOptionsForm.cs</DependentUpon>
</EmbeddedResource>