mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-04 04:06:05 +13:00
Merge pull request #5146 from 7coil/master
Add canvas margin from percentage canvas size
This commit is contained in:
commit
b47687f9fe
1 changed files with 28 additions and 1 deletions
|
@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
|
|||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Design;
|
||||
|
@ -36,6 +37,9 @@ internal class Canvas : ImageEffect
|
|||
[DefaultValue(typeof(Padding), "0, 0, 0, 0")]
|
||||
public Padding Margin { get; set; }
|
||||
|
||||
[DefaultValue(CanvasMarginMode.AbsoluteSize), Description("How the margin around the canvas will be calculated."), TypeConverter(typeof(EnumDescriptionConverter))]
|
||||
public CanvasMarginMode MarginMode { get; set; }
|
||||
|
||||
[DefaultValue(typeof(Color), "Transparent"), Editor(typeof(MyColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(MyColorConverter))]
|
||||
public Color Color { get; set; }
|
||||
|
||||
|
@ -44,9 +48,32 @@ public Canvas()
|
|||
this.ApplyDefaultPropertyValues();
|
||||
}
|
||||
|
||||
public enum CanvasMarginMode
|
||||
{
|
||||
AbsoluteSize,
|
||||
PercentageOfCanvas
|
||||
}
|
||||
|
||||
public override Bitmap Apply(Bitmap bmp)
|
||||
{
|
||||
Bitmap bmpResult = ImageHelpers.AddCanvas(bmp, Margin, Color);
|
||||
Padding canvasMargin;
|
||||
|
||||
if (MarginMode == CanvasMarginMode.PercentageOfCanvas)
|
||||
{
|
||||
// Calculate the amount of padding to add to the sides, based on canvas size.
|
||||
canvasMargin = new Padding();
|
||||
canvasMargin.Top = (int)Math.Round(Margin.Top / 100f * bmp.Height);
|
||||
canvasMargin.Bottom = (int)Math.Round(Margin.Bottom / 100f * bmp.Height);
|
||||
canvasMargin.Left = (int)Math.Round(Margin.Left / 100f * bmp.Width);
|
||||
canvasMargin.Right = (int)Math.Round(Margin.Right / 100f * bmp.Width);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the margin as is (absolute size)
|
||||
canvasMargin = Margin;
|
||||
}
|
||||
|
||||
Bitmap bmpResult = ImageHelpers.AddCanvas(bmp, canvasMargin, Color);
|
||||
|
||||
if (bmpResult == null)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue