mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
#3304: After move image if image is outside canvas then resize canvas to fit image
This commit is contained in:
parent
eb2150ae32
commit
5bfbc07818
4 changed files with 35 additions and 5 deletions
|
@ -274,6 +274,12 @@ public static Bitmap AutoCropTransparent(Bitmap bmp)
|
|||
}
|
||||
}
|
||||
|
||||
// If all pixels transparent
|
||||
if (!leave)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
|
||||
leave = false;
|
||||
|
||||
// Find Y
|
||||
|
|
|
@ -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,7 +322,10 @@ internal void InitBackground(Image canvas)
|
|||
backgroundBrush.TranslateTransform(CanvasRectangle.X, CanvasRectangle.Y);
|
||||
}
|
||||
|
||||
CenterCanvas();
|
||||
if (centerCanvas)
|
||||
{
|
||||
CenterCanvas();
|
||||
}
|
||||
}
|
||||
else if (!IsEditorMode && Options.UseDimming)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue