mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-30 12:11:07 +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>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Drawing: Ellipse.
|
/// Looks up a localized string similar to Drawing: Ellipse.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -995,4 +995,7 @@ Would you like to download it?</value>
|
||||||
<data name="DownloaderForm_ChangeProgress_Progress___0_" xml:space="preserve">
|
<data name="DownloaderForm_ChangeProgress_Progress___0_" xml:space="preserve">
|
||||||
<value>Progress: {0}</value>
|
<value>Progress: {0}</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="ShapeType_DrawingCrop" xml:space="preserve">
|
||||||
|
<value>Crop image</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -231,7 +231,8 @@ public enum ShapeType // Localized
|
||||||
DrawingImage,
|
DrawingImage,
|
||||||
EffectBlur,
|
EffectBlur,
|
||||||
EffectPixelate,
|
EffectPixelate,
|
||||||
EffectHighlight
|
EffectHighlight,
|
||||||
|
DrawingCrop
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum RegionAnnotateMode
|
public enum RegionAnnotateMode
|
||||||
|
|
|
@ -160,6 +160,32 @@ public void Prepare()
|
||||||
// Must be called before show form
|
// Must be called before show form
|
||||||
public void Prepare(Image img)
|
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;
|
Image = img;
|
||||||
|
|
||||||
if (IsEditorMode)
|
if (IsEditorMode)
|
||||||
|
@ -206,25 +232,9 @@ public void Prepare(Image img)
|
||||||
backgroundBrush = new TextureBrush(Image) { WrapMode = WrapMode.Clamp };
|
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 (Config.UseCustomInfoText || Mode == RegionCaptureMode.ScreenColorPicker)
|
||||||
{
|
{
|
||||||
|
if (bmpBackgroundImage != null) bmpBackgroundImage.Dispose();
|
||||||
bmpBackgroundImage = new Bitmap(Image);
|
bmpBackgroundImage = new Bitmap(Image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,19 +318,19 @@ private void MonitorKey(int index)
|
||||||
Close(RegionResult.Monitor);
|
Close(RegionResult.Monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close(RegionResult result)
|
internal void Close(RegionResult result)
|
||||||
{
|
{
|
||||||
Result = result;
|
Result = result;
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Pause()
|
internal void Pause()
|
||||||
{
|
{
|
||||||
pause = true;
|
pause = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Resume()
|
internal void Resume()
|
||||||
{
|
{
|
||||||
pause = false;
|
pause = false;
|
||||||
|
|
||||||
|
@ -517,8 +527,7 @@ private void Draw(Graphics g)
|
||||||
// Draw animated rectangle on selection area
|
// Draw animated rectangle on selection area
|
||||||
if (ShapeManager.IsCurrentShapeTypeRegion && ShapeManager.IsCurrentShapeValid)
|
if (ShapeManager.IsCurrentShapeTypeRegion && ShapeManager.IsCurrentShapeValid)
|
||||||
{
|
{
|
||||||
g.DrawRectangleProper(borderPen, ShapeManager.CurrentRectangle);
|
DrawRegionArea(g, ShapeManager.CurrentRectangle);
|
||||||
g.DrawRectangleProper(borderDotPen, ShapeManager.CurrentRectangle);
|
|
||||||
|
|
||||||
if (Mode == RegionCaptureMode.Ruler)
|
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)
|
private void DrawObjects(Graphics g)
|
||||||
{
|
{
|
||||||
foreach (DrawableObject drawObject in DrawableObjects)
|
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)
|
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>
|
/// <summary>
|
||||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||||
/// </summary>
|
/// </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">
|
<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>
|
<value>..\Resources\cross.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
</data>
|
</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>
|
</root>
|
|
@ -180,9 +180,9 @@ public static void ShowScreenRuler(RegionCaptureOptions options)
|
||||||
case RegionResult.Region: // Enter
|
case RegionResult.Region: // Enter
|
||||||
case RegionResult.AnnotateRunAfterCaptureTasks:
|
case RegionResult.AnnotateRunAfterCaptureTasks:
|
||||||
return form.GetResultImage();
|
return form.GetResultImage();
|
||||||
case RegionResult.Fullscreen: // Space
|
case RegionResult.Fullscreen: // Space or right click
|
||||||
case RegionResult.AnnotateContinueTask:
|
case RegionResult.AnnotateContinueTask:
|
||||||
return (Image)img.Clone();
|
return (Image)form.Image.Clone();
|
||||||
case RegionResult.AnnotateSaveImage:
|
case RegionResult.AnnotateSaveImage:
|
||||||
using (Image resultSaveImage = form.GetResultImage())
|
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:
|
case ShapeType.DrawingImage:
|
||||||
shape = new ImageDrawingShape();
|
shape = new ImageDrawingShape();
|
||||||
break;
|
break;
|
||||||
|
case ShapeType.DrawingCrop:
|
||||||
|
shape = new CropDrawingShape();
|
||||||
|
break;
|
||||||
case ShapeType.EffectBlur:
|
case ShapeType.EffectBlur:
|
||||||
shape = new BlurEffectShape();
|
shape = new BlurEffectShape();
|
||||||
break;
|
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)
|
private void OnCurrentShapeChanged(BaseShape shape)
|
||||||
{
|
{
|
||||||
if (CurrentShapeChanged != null)
|
if (CurrentShapeChanged != null)
|
||||||
|
|
|
@ -211,6 +211,10 @@ private void CreateToolbar()
|
||||||
{
|
{
|
||||||
tsMain.Items.Add(new ToolStripSeparator());
|
tsMain.Items.Add(new ToolStripSeparator());
|
||||||
}
|
}
|
||||||
|
else if (shapeType == ShapeType.DrawingCrop)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ToolStripButton tsbShapeType = new ToolStripButton(shapeType.GetLocalizedDescription());
|
ToolStripButton tsbShapeType = new ToolStripButton(shapeType.GetLocalizedDescription());
|
||||||
tsbShapeType.DisplayStyle = ToolStripItemDisplayStyle.Image;
|
tsbShapeType.DisplayStyle = ToolStripItemDisplayStyle.Image;
|
||||||
|
@ -258,6 +262,9 @@ private void CreateToolbar()
|
||||||
case ShapeType.DrawingImage:
|
case ShapeType.DrawingImage:
|
||||||
img = Resources.image;
|
img = Resources.image;
|
||||||
break;
|
break;
|
||||||
|
case ShapeType.DrawingCrop:
|
||||||
|
img = Resources.image_crop;
|
||||||
|
break;
|
||||||
case ShapeType.EffectBlur:
|
case ShapeType.EffectBlur:
|
||||||
img = Resources.layer_shade;
|
img = Resources.layer_shade;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -113,6 +113,7 @@
|
||||||
<Compile Include="Animations\OpacityAnimation.cs" />
|
<Compile Include="Animations\OpacityAnimation.cs" />
|
||||||
<Compile Include="Shapes\BaseShape.cs" />
|
<Compile Include="Shapes\BaseShape.cs" />
|
||||||
<Compile Include="Shapes\Drawing\ArrowDrawingShape.cs" />
|
<Compile Include="Shapes\Drawing\ArrowDrawingShape.cs" />
|
||||||
|
<Compile Include="Shapes\Drawing\CropDrawingShape.cs" />
|
||||||
<Compile Include="Shapes\Drawing\SpeechBalloonDrawingShape.cs" />
|
<Compile Include="Shapes\Drawing\SpeechBalloonDrawingShape.cs" />
|
||||||
<Compile Include="Shapes\Drawing\BaseDrawingShape.cs" />
|
<Compile Include="Shapes\Drawing\BaseDrawingShape.cs" />
|
||||||
<Compile Include="Shapes\Drawing\FreehandDrawingShape.cs" />
|
<Compile Include="Shapes\Drawing\FreehandDrawingShape.cs" />
|
||||||
|
@ -187,6 +188,7 @@
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include="Resources\image-crop.png" />
|
||||||
<None Include="Resources\edit-shade.png" />
|
<None Include="Resources\edit-shade.png" />
|
||||||
<None Include="Resources\edit-outline.png" />
|
<None Include="Resources\edit-outline.png" />
|
||||||
<None Include="Resources\pencil.png" />
|
<None Include="Resources\pencil.png" />
|
||||||
|
|
Loading…
Reference in a new issue