#3304: After move image if image is outside canvas then resize canvas to fit image

This commit is contained in:
Jaex 2018-04-13 14:56:35 +03:00
parent eb2150ae32
commit 5bfbc07818
4 changed files with 35 additions and 5 deletions

View file

@ -274,6 +274,12 @@ public static Bitmap AutoCropTransparent(Bitmap bmp)
}
}
// If all pixels transparent
if (!leave)
{
return bmp;
}
leave = false;
// Find Y

View file

@ -49,7 +49,7 @@ public sealed class RegionCaptureForm : Form
public RegionCaptureOptions Options { get; set; }
public Rectangle ClientArea { get; private set; }
public Image Canvas { get; private set; }
public Rectangle CanvasRectangle { get; private set; }
public Rectangle CanvasRectangle { get; internal set; }
public RegionResult Result { get; private set; }
public int FPS { get; private set; }
public int MonitorIndex { get; set; }
@ -292,7 +292,7 @@ private void Prepare(Image canvas = null)
}
}
internal void InitBackground(Image canvas)
internal void InitBackground(Image canvas, bool centerCanvas = true)
{
if (Canvas != null) Canvas.Dispose();
if (backgroundBrush != null) backgroundBrush.Dispose();
@ -322,8 +322,11 @@ internal void InitBackground(Image canvas)
backgroundBrush.TranslateTransform(CanvasRectangle.X, CanvasRectangle.Y);
}
if (centerCanvas)
{
CenterCanvas();
}
}
else if (!IsEditorMode && Options.UseDimming)
{
using (Bitmap darkBackground = (Bitmap)Canvas.Clone())

View file

@ -23,8 +23,11 @@ You should have received a copy of the GNU General Public License
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace ShareX.ScreenCaptureLib
{
@ -88,6 +91,24 @@ protected void DrawImage(Graphics g)
}
}
public override void OnMoved()
{
Rectangle canvas = Manager.Form.CanvasRectangle;
if (!canvas.Contains(Rectangle))
{
Padding margin = new Padding(Math.Max(0, canvas.X - Rectangle.X), Math.Max(0, canvas.Y - Rectangle.Y),
Math.Max(0, Rectangle.Right - canvas.Right), Math.Max(0, Rectangle.Bottom - canvas.Bottom));
Image img = ImageHelpers.AddCanvas(Manager.Form.Canvas, margin);
if (img != null)
{
Manager.Form.CanvasRectangle = Manager.Form.CanvasRectangle.LocationOffset(-margin.Left, -margin.Top);
Manager.UpdateCanvas(img, false);
}
}
}
public override void Dispose()
{
if (Image != null)

View file

@ -1540,9 +1540,9 @@ public void DrawRegionArea(Graphics g, Rectangle rect, bool isAnimated, bool sho
}
}
private void UpdateCanvas(Image img)
public void UpdateCanvas(Image img, bool centerCanvas = true)
{
Form.InitBackground(img);
Form.InitBackground(img, centerCanvas);
foreach (BaseEffectShape effect in EffectShapes)
{