2013-11-03 23:53:49 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2016-01-04 04:16:01 +13:00
|
|
|
|
Copyright (c) 2007-2016 ShareX Team
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
using ShareX.HelpersLib;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Drawing2D;
|
2016-05-15 19:12:53 +12:00
|
|
|
|
using System.Windows.Forms;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-15 19:12:53 +12:00
|
|
|
|
public static class RegionCaptureHelpers
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-15 19:34:02 +12:00
|
|
|
|
public static Image GetRegionImage()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-15 19:34:02 +12:00
|
|
|
|
using (RectangleRegionForm form = new RectangleRegionForm(RectangleRegionMode.Default))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-15 19:34:02 +12:00
|
|
|
|
form.Config.ShowTips = false;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-05-15 19:34:02 +12:00
|
|
|
|
form.Prepare();
|
|
|
|
|
form.ShowDialog();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-05-15 19:34:02 +12:00
|
|
|
|
return form.GetResultImage();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-15 19:12:53 +12:00
|
|
|
|
|
2016-05-15 19:34:02 +12:00
|
|
|
|
public static bool GetRectangleRegion(out Rectangle rect)
|
2016-05-15 19:12:53 +12:00
|
|
|
|
{
|
|
|
|
|
using (RectangleRegionForm form = new RectangleRegionForm(RectangleRegionMode.Default))
|
|
|
|
|
{
|
|
|
|
|
form.Config.ShowTips = false;
|
|
|
|
|
|
|
|
|
|
form.Prepare();
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
|
|
|
|
|
if (form.Result == RegionResult.Region)
|
|
|
|
|
{
|
2016-08-09 10:05:01 +12:00
|
|
|
|
if (form.ShapeManager.IsCurrentShapeValid)
|
2016-05-15 19:12:53 +12:00
|
|
|
|
{
|
|
|
|
|
rect = CaptureHelpers.ClientToScreen(form.ShapeManager.CurrentRectangle);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (form.Result == RegionResult.Fullscreen)
|
|
|
|
|
{
|
|
|
|
|
rect = CaptureHelpers.GetScreenBounds();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (form.Result == RegionResult.Monitor)
|
|
|
|
|
{
|
|
|
|
|
Screen[] screens = Screen.AllScreens;
|
|
|
|
|
|
|
|
|
|
if (form.MonitorIndex < screens.Length)
|
|
|
|
|
{
|
|
|
|
|
Screen screen = screens[form.MonitorIndex];
|
|
|
|
|
rect = screen.Bounds;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (form.Result == RegionResult.ActiveMonitor)
|
|
|
|
|
{
|
|
|
|
|
rect = CaptureHelpers.GetActiveScreenBounds();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rect = Rectangle.Empty;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-05-15 19:34:02 +12:00
|
|
|
|
|
|
|
|
|
public static PointInfo GetPointInfo()
|
|
|
|
|
{
|
|
|
|
|
using (RectangleRegionForm form = new RectangleRegionForm(RectangleRegionMode.ScreenColorPicker))
|
|
|
|
|
{
|
|
|
|
|
form.Config.DetectWindows = false;
|
|
|
|
|
form.Config.ShowTips = false;
|
|
|
|
|
form.Config.UseDimming = false;
|
|
|
|
|
|
|
|
|
|
form.Prepare();
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
|
|
|
|
|
if (form.Result == RegionResult.Region)
|
|
|
|
|
{
|
|
|
|
|
PointInfo pointInfo = new PointInfo();
|
|
|
|
|
pointInfo.Position = form.CurrentPosition;
|
|
|
|
|
pointInfo.Color = form.CurrentColor;
|
|
|
|
|
return pointInfo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static SimpleWindowInfo GetWindowInfo()
|
|
|
|
|
{
|
|
|
|
|
using (RectangleRegionForm form = new RectangleRegionForm(RectangleRegionMode.OneClick))
|
|
|
|
|
{
|
|
|
|
|
form.Config.UseDimming = false;
|
|
|
|
|
form.Config.ShowMagnifier = false;
|
|
|
|
|
form.Config.ShowTips = false;
|
|
|
|
|
|
|
|
|
|
form.Prepare();
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
|
|
|
|
|
if (form.Result == RegionResult.Region)
|
|
|
|
|
{
|
|
|
|
|
return form.SelectedWindow;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ShowScreenRuler()
|
|
|
|
|
{
|
|
|
|
|
using (RectangleRegionForm form = new RectangleRegionForm(RectangleRegionMode.Ruler))
|
|
|
|
|
{
|
|
|
|
|
form.Config.QuickCrop = false;
|
|
|
|
|
form.Config.ShowTips = false;
|
|
|
|
|
|
|
|
|
|
form.Prepare();
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-02 20:29:17 +12:00
|
|
|
|
public static Image ApplyRegionPathToImage(Image img, GraphicsPath gp)
|
2016-05-15 19:34:02 +12:00
|
|
|
|
{
|
2016-08-02 20:29:17 +12:00
|
|
|
|
if (img != null && gp != null)
|
2016-05-15 19:34:02 +12:00
|
|
|
|
{
|
2016-08-02 20:29:17 +12:00
|
|
|
|
Rectangle regionArea = Rectangle.Round(gp.GetBounds());
|
2016-05-15 19:34:02 +12:00
|
|
|
|
Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based();
|
2016-08-02 20:29:17 +12:00
|
|
|
|
regionArea = Rectangle.Intersect(regionArea, screenRectangle);
|
2016-05-15 19:34:02 +12:00
|
|
|
|
|
2016-08-02 20:29:17 +12:00
|
|
|
|
if (regionArea.IsValid())
|
2016-05-15 19:34:02 +12:00
|
|
|
|
{
|
2016-08-02 20:29:17 +12:00
|
|
|
|
using (Bitmap bmp = img.CreateEmptyBitmap())
|
|
|
|
|
using (Graphics g = Graphics.FromImage(bmp))
|
|
|
|
|
using (TextureBrush brush = new TextureBrush(img))
|
2016-05-15 19:34:02 +12:00
|
|
|
|
{
|
2016-08-02 20:29:17 +12:00
|
|
|
|
g.PixelOffsetMode = PixelOffsetMode.Half;
|
|
|
|
|
g.SmoothingMode = SmoothingMode.HighQuality;
|
2016-05-16 21:48:53 +12:00
|
|
|
|
|
2016-08-02 20:29:17 +12:00
|
|
|
|
g.FillPath(brush, gp);
|
2016-05-15 19:34:02 +12:00
|
|
|
|
|
2016-08-02 20:29:17 +12:00
|
|
|
|
return ImageHelpers.CropBitmap(bmp, regionArea);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-15 19:34:02 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|