mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Adding image paste (ctrl + v) support to region capture
This commit is contained in:
parent
029d63f457
commit
72693d46d1
4 changed files with 87 additions and 1 deletions
|
@ -179,6 +179,7 @@ public enum ShapeType // Localized
|
|||
DrawingArrow,
|
||||
DrawingText,
|
||||
DrawingStep,
|
||||
DrawingImage,
|
||||
DrawingBlur,
|
||||
DrawingPixelate,
|
||||
DrawingHighlight
|
||||
|
|
56
ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs
Normal file
56
ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs
Normal file
|
@ -0,0 +1,56 @@
|
|||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
Copyright (c) 2007-2016 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 System.Drawing;
|
||||
|
||||
namespace ShareX.ScreenCaptureLib
|
||||
{
|
||||
public class ImageDrawingShape : BaseDrawingShape
|
||||
{
|
||||
public override ShapeType ShapeType { get; } = ShapeType.DrawingImage;
|
||||
|
||||
public Image Image { get; private set; }
|
||||
|
||||
public void SetImage(Image img, Point pos)
|
||||
{
|
||||
if (Image != null)
|
||||
{
|
||||
Image.Dispose();
|
||||
}
|
||||
|
||||
Image = img;
|
||||
|
||||
Rectangle = new Rectangle(new Point(pos.X - Image.Width / 2, pos.Y - Image.Height / 2), Image.Size);
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics g)
|
||||
{
|
||||
if (Image != null)
|
||||
{
|
||||
g.DrawImage(Image, Rectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1109,6 +1109,9 @@ private void form_KeyUp(object sender, KeyEventArgs e)
|
|||
Config.QuickCrop = !Config.QuickCrop;
|
||||
tsmiQuickCrop.Checked = !Config.QuickCrop;
|
||||
break;
|
||||
case Keys.Control | Keys.V:
|
||||
AddImageFromClipboard();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1256,9 +1259,14 @@ private void EndRegionSelection()
|
|||
private BaseShape AddShape()
|
||||
{
|
||||
BaseShape shape = CreateShape();
|
||||
AddShape(shape);
|
||||
return shape;
|
||||
}
|
||||
|
||||
private void AddShape(BaseShape shape)
|
||||
{
|
||||
Shapes.Add(shape);
|
||||
CurrentShape = shape;
|
||||
return shape;
|
||||
}
|
||||
|
||||
private BaseShape CreateShape()
|
||||
|
@ -1309,6 +1317,9 @@ private BaseShape CreateShape(ShapeType shapeType)
|
|||
case ShapeType.DrawingStep:
|
||||
shape = new StepDrawingShape();
|
||||
break;
|
||||
case ShapeType.DrawingImage:
|
||||
shape = new ImageDrawingShape();
|
||||
break;
|
||||
case ShapeType.DrawingBlur:
|
||||
shape = new BlurEffectShape();
|
||||
break;
|
||||
|
@ -1687,6 +1698,23 @@ public void OrderStepShapes()
|
|||
}
|
||||
}
|
||||
|
||||
private void AddImageFromClipboard()
|
||||
{
|
||||
if (Clipboard.ContainsImage())
|
||||
{
|
||||
Image img = ClipboardHelpers.GetImage();
|
||||
|
||||
if (img != null)
|
||||
{
|
||||
CurrentShapeType = ShapeType.DrawingImage;
|
||||
ImageDrawingShape shape = (ImageDrawingShape)CreateShape(ShapeType.DrawingImage);
|
||||
shape.SetImage(img, InputManager.MousePosition0Based);
|
||||
AddShape(shape);
|
||||
SelectCurrentShape();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCurrentShapeChanged(BaseShape shape)
|
||||
{
|
||||
if (CurrentShapeChanged != null)
|
||||
|
|
|
@ -93,6 +93,7 @@
|
|||
<Compile Include="Shapes\Drawing\ArrowDrawingShape.cs" />
|
||||
<Compile Include="Shapes\Drawing\BaseDrawingShape.cs" />
|
||||
<Compile Include="Shapes\Drawing\FreehandDrawingShape.cs" />
|
||||
<Compile Include="Shapes\Drawing\ImageDrawingShape.cs" />
|
||||
<Compile Include="Shapes\Drawing\StepDrawingShape.cs" />
|
||||
<Compile Include="Shapes\Region\FreehandRegionShape.cs" />
|
||||
<Compile Include="Shapes\TextDrawingOptions.cs" />
|
||||
|
|
Loading…
Reference in a new issue