/// <summary> /// 点在区域中是否可见(现已废弃,替代方法 PointInPolygon) /// </summary> /// <param name="point"></param> /// <param name="pointColl"></param> /// <returns></returns> public static bool IsVisible_Region(Point point, List <Point> pointColl) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Region region = new System.Drawing.Region(); List <System.Drawing.Point> pathPoints = new List <System.Drawing.Point>(); foreach (var pathPoint in pointColl) { pathPoints.Add(new System.Drawing.Point((int)Math.Round(pathPoint.X), (int)Math.Round(pathPoint.Y))); } path.AddPolygon(pathPoints.ToArray()); path.CloseFigure(); region.MakeEmpty(); region.Union(path); return(region.IsVisible(new System.Drawing.Point((int)Math.Round(point.X), (int)Math.Round(point.Y)))); }
private System.Drawing.Region BuildRegionFromBitmap(BitmapSource bitmap, Point offset) { var region = new System.Drawing.Region(); region.MakeEmpty(); var rectangle = System.Drawing.Rectangle.Empty; bool inImage = false; for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { var croppedPixel = new CroppedBitmap(bitmap, new Int32Rect(x, y, 1, 1)); byte[] pixel = new byte[bitmap.Format.BitsPerPixel / 8]; croppedPixel.CopyPixels(pixel, bitmap.Format.BitsPerPixel / 8, 0); var pixelAlpha = pixel[0]; if (!inImage && pixelAlpha > 0) { inImage = true; rectangle.X = x; rectangle.Y = y; rectangle.Height = 1; } else if (inImage && pixelAlpha == 0) { inImage = false; rectangle.Width = x - rectangle.X; rectangle.Offset((int)offset.X, (int)offset.Y); region.Union(rectangle); } } if (inImage) { inImage = false; rectangle.Width = (int)bitmap.Width - rectangle.X; rectangle.Offset((int)offset.X, (int)offset.Y); region.Union(rectangle); } } return(region); }
public Area() { region = new System.Drawing.Region(); region.MakeEmpty(); }
public Area() { region = new System.Drawing.Region(); region.MakeEmpty(); }