mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Apply region path to image with anti aliasing
This commit is contained in:
parent
a1a1c1ef17
commit
24ada5cc9a
5 changed files with 16 additions and 61 deletions
|
@ -243,30 +243,6 @@ public static Bitmap CropBitmap(Bitmap bmp, Rectangle rect)
|
|||
return null;
|
||||
}
|
||||
|
||||
public static Image CropImage(Image img, Rectangle rect, GraphicsPath gp)
|
||||
{
|
||||
if (img != null && rect.Width > 0 && rect.Height > 0 && gp != null)
|
||||
{
|
||||
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
|
||||
bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution);
|
||||
|
||||
using (Graphics g = Graphics.FromImage(bmp))
|
||||
{
|
||||
g.SetHighQuality();
|
||||
|
||||
using (Region region = new Region(gp))
|
||||
{
|
||||
g.Clip = region;
|
||||
g.DrawImage(img, new Rectangle(0, 0, rect.Width, rect.Height), rect, GraphicsUnit.Pixel);
|
||||
}
|
||||
}
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Image DrawOutline(Image img, GraphicsPath gp)
|
||||
{
|
||||
if (img != null && gp != null)
|
||||
|
|
|
@ -232,7 +232,7 @@ public virtual Image GetResultImage()
|
|||
{
|
||||
using (Image img = GetOutputImage())
|
||||
{
|
||||
return RegionCaptureHelpers.ApplyRegionPathToImage(img, regionFillPath, Config);
|
||||
return RegionCaptureHelpers.ApplyRegionPathToImage(img, regionFillPath);
|
||||
}
|
||||
}
|
||||
else if (Result == RegionResult.Fullscreen)
|
||||
|
|
|
@ -24,7 +24,6 @@ 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;
|
||||
|
@ -145,29 +144,28 @@ public static void ShowScreenRuler()
|
|||
}
|
||||
}
|
||||
|
||||
public static Image ApplyRegionPathToImage(Image backgroundImage, GraphicsPath regionFillPath, RegionCaptureOptions options)
|
||||
public static Image ApplyRegionPathToImage(Image img, GraphicsPath gp)
|
||||
{
|
||||
if (backgroundImage != null && regionFillPath != null)
|
||||
if (img != null && gp != null)
|
||||
{
|
||||
Image img;
|
||||
|
||||
Rectangle regionArea = Rectangle.Round(regionFillPath.GetBounds());
|
||||
Rectangle regionArea = Rectangle.Round(gp.GetBounds());
|
||||
Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based();
|
||||
Rectangle newRegionArea = Rectangle.Intersect(regionArea, screenRectangle);
|
||||
regionArea = Rectangle.Intersect(regionArea, screenRectangle);
|
||||
|
||||
using (GraphicsPath gp = (GraphicsPath)regionFillPath.Clone())
|
||||
if (regionArea.IsValid())
|
||||
{
|
||||
using (Matrix matrix = new Matrix())
|
||||
using (Bitmap bmp = img.CreateEmptyBitmap())
|
||||
using (Graphics g = Graphics.FromImage(bmp))
|
||||
using (TextureBrush brush = new TextureBrush(img))
|
||||
{
|
||||
gp.CloseFigure();
|
||||
matrix.Translate(-Math.Max(0, regionArea.X), -Math.Max(0, regionArea.Y));
|
||||
gp.Transform(matrix);
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
|
||||
g.FillPath(brush, gp);
|
||||
|
||||
return ImageHelpers.CropBitmap(bmp, regionArea);
|
||||
}
|
||||
|
||||
img = ImageHelpers.CropImage(backgroundImage, newRegionArea, gp);
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -1479,25 +1479,6 @@ public bool IsShapeIntersect()
|
|||
return GetShapeIntersect() != null;
|
||||
}
|
||||
|
||||
public Rectangle CombineAreas()
|
||||
{
|
||||
BaseShape[] areas = ValidRegions;
|
||||
|
||||
if (areas.Length > 0)
|
||||
{
|
||||
Rectangle rect = areas[0].Rectangle;
|
||||
|
||||
for (int i = 1; i < areas.Length; i++)
|
||||
{
|
||||
rect = Rectangle.Union(rect, areas[i].Rectangle);
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
return Rectangle.Empty;
|
||||
}
|
||||
|
||||
private void UpdateCursor()
|
||||
{
|
||||
try
|
||||
|
|
|
@ -2282,7 +2282,7 @@ private void CaptureLastRegion(TaskSettings taskSettings, bool autoHideForm = tr
|
|||
{
|
||||
using (Image screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen())
|
||||
{
|
||||
return RegionCaptureHelpers.ApplyRegionPathToImage(screenshot, BaseRegionForm.LastRegionFillPath, taskSettings.CaptureSettings.SurfaceOptions);
|
||||
return RegionCaptureHelpers.ApplyRegionPathToImage(screenshot, BaseRegionForm.LastRegionFillPath);
|
||||
}
|
||||
}, CaptureType.LastRegion, taskSettings, autoHideForm);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue