public static Image GetRegionImage(Image surfaceImage, GraphicsPath regionFillPath, GraphicsPath regionDrawPath, SurfaceOptions options) { if (regionFillPath != null) { Image img; Rectangle regionArea = Rectangle.Round(regionFillPath.GetBounds()); Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based(); Rectangle newRegionArea = Rectangle.Intersect(regionArea, screenRectangle); using (GraphicsPath gp = (GraphicsPath)regionFillPath.Clone()) { MoveGraphicsPath(gp, -Math.Max(0, regionArea.X), -Math.Max(0, regionArea.Y)); img = ImageHelpers.CropImage(surfaceImage, newRegionArea, gp); if (options.DrawBorder) { GraphicsPath gpOutline = regionDrawPath ?? regionFillPath; using (GraphicsPath gp2 = (GraphicsPath)gpOutline.Clone()) { MoveGraphicsPath(gp2, -Math.Max(0, regionArea.X), -Math.Max(0, regionArea.Y)); img = ImageHelpers.DrawOutline(img, gp2); } } } return(img); } return(null); }
public static Image ApplyRegionPathToImage(Image img, GraphicsPath gp) { if (img != null && gp != null) { Rectangle regionArea = Rectangle.Round(gp.GetBounds()); Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based(); regionArea = Rectangle.Intersect(regionArea, screenRectangle); if (regionArea.IsValid()) { using (Bitmap bmp = img.CreateEmptyBitmap()) using (Graphics g = Graphics.FromImage(bmp)) using (TextureBrush brush = new TextureBrush(img)) { g.PixelOffsetMode = PixelOffsetMode.Half; g.SmoothingMode = SmoothingMode.HighQuality; g.FillPath(brush, gp); return(ImageHelpers.CropBitmap(bmp, regionArea)); } } } return(null); }
public static Image ApplyRegionPathToImage(Image backgroundImage, GraphicsPath regionFillPath, SurfaceOptions options) { if (backgroundImage != null && regionFillPath != null) { Image img; Rectangle regionArea = Rectangle.Round(regionFillPath.GetBounds()); Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based(); Rectangle newRegionArea = Rectangle.Intersect(regionArea, screenRectangle); using (GraphicsPath gp = (GraphicsPath)regionFillPath.Clone()) { using (Matrix matrix = new Matrix()) { gp.CloseFigure(); matrix.Translate(-Math.Max(0, regionArea.X), -Math.Max(0, regionArea.Y)); gp.Transform(matrix); } img = ImageHelpers.CropImage(backgroundImage, newRegionArea, gp); } return(img); } return(null); }