mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-28 03:00:22 +12:00
fixed #2479: Added crop tool to annotation
This commit is contained in:
parent
24e02e894b
commit
67a218bee9
|
@ -2401,6 +2401,15 @@ internal class Resources {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Crop image.
|
||||
/// </summary>
|
||||
internal static string ShapeType_DrawingCrop {
|
||||
get {
|
||||
return ResourceManager.GetString("ShapeType_DrawingCrop", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Drawing: Ellipse.
|
||||
/// </summary>
|
||||
|
|
|
@ -995,4 +995,7 @@ Would you like to download it?</value>
|
|||
<data name="DownloaderForm_ChangeProgress_Progress___0_" xml:space="preserve">
|
||||
<value>Progress: {0}</value>
|
||||
</data>
|
||||
<data name="ShapeType_DrawingCrop" xml:space="preserve">
|
||||
<value>Crop image</value>
|
||||
</data>
|
||||
</root>
|
|
@ -231,7 +231,8 @@ public enum ShapeType // Localized
|
|||
DrawingImage,
|
||||
EffectBlur,
|
||||
EffectPixelate,
|
||||
EffectHighlight
|
||||
EffectHighlight,
|
||||
DrawingCrop
|
||||
}
|
||||
|
||||
public enum RegionAnnotateMode
|
||||
|
|
|
@ -160,6 +160,32 @@ public void Prepare()
|
|||
// Must be called before show form
|
||||
public void Prepare(Image img)
|
||||
{
|
||||
InitBackground(img);
|
||||
|
||||
ShapeManager = new ShapeManager(this);
|
||||
ShapeManager.WindowCaptureMode = Config.DetectWindows;
|
||||
ShapeManager.IncludeControls = Config.DetectControls;
|
||||
|
||||
if (Mode == RegionCaptureMode.OneClick || ShapeManager.WindowCaptureMode)
|
||||
{
|
||||
IntPtr handle = Handle;
|
||||
|
||||
TaskEx.Run(() =>
|
||||
{
|
||||
WindowsRectangleList wla = new WindowsRectangleList();
|
||||
wla.IgnoreHandle = handle;
|
||||
wla.IncludeChildWindows = ShapeManager.IncludeControls;
|
||||
ShapeManager.Windows = wla.GetWindowInfoListAsync(5000);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal void InitBackground(Image img)
|
||||
{
|
||||
if (Image != null) Image.Dispose();
|
||||
if (backgroundBrush != null) backgroundBrush.Dispose();
|
||||
if (backgroundHighlightBrush != null) backgroundHighlightBrush.Dispose();
|
||||
|
||||
Image = img;
|
||||
|
||||
if (IsEditorMode)
|
||||
|
@ -206,25 +232,9 @@ public void Prepare(Image img)
|
|||
backgroundBrush = new TextureBrush(Image) { WrapMode = WrapMode.Clamp };
|
||||
}
|
||||
|
||||
ShapeManager = new ShapeManager(this);
|
||||
ShapeManager.WindowCaptureMode = Config.DetectWindows;
|
||||
ShapeManager.IncludeControls = Config.DetectControls;
|
||||
|
||||
if (Mode == RegionCaptureMode.OneClick || ShapeManager.WindowCaptureMode)
|
||||
{
|
||||
IntPtr handle = Handle;
|
||||
|
||||
TaskEx.Run(() =>
|
||||
{
|
||||
WindowsRectangleList wla = new WindowsRectangleList();
|
||||
wla.IgnoreHandle = handle;
|
||||
wla.IncludeChildWindows = ShapeManager.IncludeControls;
|
||||
ShapeManager.Windows = wla.GetWindowInfoListAsync(5000);
|
||||
});
|
||||
}
|
||||
|
||||
if (Config.UseCustomInfoText || Mode == RegionCaptureMode.ScreenColorPicker)
|
||||
{
|
||||
if (bmpBackgroundImage != null) bmpBackgroundImage.Dispose();
|
||||
bmpBackgroundImage = new Bitmap(Image);
|
||||
}
|
||||
}
|
||||
|
@ -308,19 +318,19 @@ private void MonitorKey(int index)
|
|||
Close(RegionResult.Monitor);
|
||||
}
|
||||
|
||||
public void Close(RegionResult result)
|
||||
internal void Close(RegionResult result)
|
||||
{
|
||||
Result = result;
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
internal void Pause()
|
||||
{
|
||||
pause = true;
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
internal void Resume()
|
||||
{
|
||||
pause = false;
|
||||
|
||||
|
@ -517,8 +527,7 @@ private void Draw(Graphics g)
|
|||
// Draw animated rectangle on selection area
|
||||
if (ShapeManager.IsCurrentShapeTypeRegion && ShapeManager.IsCurrentShapeValid)
|
||||
{
|
||||
g.DrawRectangleProper(borderPen, ShapeManager.CurrentRectangle);
|
||||
g.DrawRectangleProper(borderDotPen, ShapeManager.CurrentRectangle);
|
||||
DrawRegionArea(g, ShapeManager.CurrentRectangle);
|
||||
|
||||
if (Mode == RegionCaptureMode.Ruler)
|
||||
{
|
||||
|
@ -592,6 +601,12 @@ private void Draw(Graphics g)
|
|||
}
|
||||
}
|
||||
|
||||
internal void DrawRegionArea(Graphics g, Rectangle rect)
|
||||
{
|
||||
g.DrawRectangleProper(borderPen, rect);
|
||||
g.DrawRectangleProper(borderDotPen, rect);
|
||||
}
|
||||
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
foreach (DrawableObject drawObject in DrawableObjects)
|
||||
|
@ -1060,7 +1075,7 @@ private void DrawRuler(Graphics g, Rectangle rect, Pen pen, int rulerSize, int r
|
|||
}
|
||||
}
|
||||
|
||||
public void UpdateRegionPath()
|
||||
internal void UpdateRegionPath()
|
||||
{
|
||||
if (regionFillPath != null)
|
||||
{
|
||||
|
|
|
@ -404,6 +404,16 @@ internal class Resources {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap image_crop {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("image_crop", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
|
|
|
@ -510,4 +510,7 @@ Distance: {6:0.00} px / Angle: {7:0.00}°</value>
|
|||
<data name="cross" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\cross.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="image_crop" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\image-crop.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
|
@ -180,9 +180,9 @@ public static void ShowScreenRuler(RegionCaptureOptions options)
|
|||
case RegionResult.Region: // Enter
|
||||
case RegionResult.AnnotateRunAfterCaptureTasks:
|
||||
return form.GetResultImage();
|
||||
case RegionResult.Fullscreen: // Space
|
||||
case RegionResult.Fullscreen: // Space or right click
|
||||
case RegionResult.AnnotateContinueTask:
|
||||
return (Image)img.Clone();
|
||||
return (Image)form.Image.Clone();
|
||||
case RegionResult.AnnotateSaveImage:
|
||||
using (Image resultSaveImage = form.GetResultImage())
|
||||
{
|
||||
|
|
BIN
ShareX.ScreenCaptureLib/Resources/image-crop.png
Normal file
BIN
ShareX.ScreenCaptureLib/Resources/image-crop.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 662 B |
45
ShareX.ScreenCaptureLib/Shapes/Drawing/CropDrawingShape.cs
Normal file
45
ShareX.ScreenCaptureLib/Shapes/Drawing/CropDrawingShape.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
#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 System.Drawing;
|
||||
|
||||
namespace ShareX.ScreenCaptureLib
|
||||
{
|
||||
public class CropDrawingShape : BaseDrawingShape
|
||||
{
|
||||
public override ShapeType ShapeType { get; } = ShapeType.DrawingCrop;
|
||||
|
||||
public override void OnDraw(Graphics g)
|
||||
{
|
||||
Manager.DrawRegionArea(g, Rectangle);
|
||||
}
|
||||
|
||||
public override void OnCreated()
|
||||
{
|
||||
Manager.CropArea(Rectangle);
|
||||
Remove();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -768,6 +768,9 @@ private BaseShape CreateShape(ShapeType shapeType)
|
|||
case ShapeType.DrawingImage:
|
||||
shape = new ImageDrawingShape();
|
||||
break;
|
||||
case ShapeType.DrawingCrop:
|
||||
shape = new CropDrawingShape();
|
||||
break;
|
||||
case ShapeType.EffectBlur:
|
||||
shape = new BlurEffectShape();
|
||||
break;
|
||||
|
@ -1219,6 +1222,31 @@ private void PasteFromClipboard()
|
|||
}
|
||||
}
|
||||
|
||||
public void DrawRegionArea(Graphics g, Rectangle rect)
|
||||
{
|
||||
form.DrawRegionArea(g, rect);
|
||||
}
|
||||
|
||||
public void CropArea(Rectangle rect)
|
||||
{
|
||||
rect.X -= form.ImageRectangle.X;
|
||||
rect.Y -= form.ImageRectangle.Y;
|
||||
|
||||
rect = CaptureHelpers.ScreenToClient(rect);
|
||||
|
||||
rect.Intersect(new Rectangle(0, 0, form.Image.Width, form.Image.Height));
|
||||
|
||||
if (rect.IsValid() && rect.Size != form.Image.Size)
|
||||
{
|
||||
Image img = ImageHelpers.CropImage(form.Image, rect);
|
||||
|
||||
if (img != null)
|
||||
{
|
||||
form.InitBackground(img);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCurrentShapeChanged(BaseShape shape)
|
||||
{
|
||||
if (CurrentShapeChanged != null)
|
||||
|
|
|
@ -211,6 +211,10 @@ private void CreateToolbar()
|
|||
{
|
||||
tsMain.Items.Add(new ToolStripSeparator());
|
||||
}
|
||||
else if (shapeType == ShapeType.DrawingCrop)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ToolStripButton tsbShapeType = new ToolStripButton(shapeType.GetLocalizedDescription());
|
||||
tsbShapeType.DisplayStyle = ToolStripItemDisplayStyle.Image;
|
||||
|
@ -258,6 +262,9 @@ private void CreateToolbar()
|
|||
case ShapeType.DrawingImage:
|
||||
img = Resources.image;
|
||||
break;
|
||||
case ShapeType.DrawingCrop:
|
||||
img = Resources.image_crop;
|
||||
break;
|
||||
case ShapeType.EffectBlur:
|
||||
img = Resources.layer_shade;
|
||||
break;
|
||||
|
|
|
@ -113,6 +113,7 @@
|
|||
<Compile Include="Animations\OpacityAnimation.cs" />
|
||||
<Compile Include="Shapes\BaseShape.cs" />
|
||||
<Compile Include="Shapes\Drawing\ArrowDrawingShape.cs" />
|
||||
<Compile Include="Shapes\Drawing\CropDrawingShape.cs" />
|
||||
<Compile Include="Shapes\Drawing\SpeechBalloonDrawingShape.cs" />
|
||||
<Compile Include="Shapes\Drawing\BaseDrawingShape.cs" />
|
||||
<Compile Include="Shapes\Drawing\FreehandDrawingShape.cs" />
|
||||
|
@ -187,6 +188,7 @@
|
|||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\image-crop.png" />
|
||||
<None Include="Resources\edit-shade.png" />
|
||||
<None Include="Resources\edit-outline.png" />
|
||||
<None Include="Resources\pencil.png" />
|
||||
|
|
Loading…
Reference in a new issue