| | |
| | | } |
| | | ZTRectangle zrect = new ZTRectangle(rect.X, rect.Y, rect.X + rect.Width - 1, rect.Y + rect.Height - 1); |
| | | rects.Add(zrect); |
| | | |
| | | |
| | | } |
| | | |
| | | return rects; |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 查找颜色数组 |
| | | /// </summary> |
| | | /// <param name="position"></param> |
| | | /// <param name="image"></param> |
| | | /// <param name="colorArray"></param> |
| | | /// <param name="limitRectangle"></param> |
| | | /// <param name="filter"></param> |
| | | /// <param name="xSkip"></param> |
| | | /// <param name="ySkip"></param> |
| | | /// <returns></returns> |
| | | public static bool FindColorArray(out ZTRectangle position, Image<Rgb, byte> image, ColorArray colorArray, ZTRectangle limitRectangle, Func<ZTRectangle, bool> filter, Int32 xSkip = 1, Int32 ySkip = 1) |
| | | { |
| | | position = ZTRectangle.Empty; |
| | | if (xSkip < 1 || ySkip < 1) |
| | | { |
| | | throw new ArgumentOutOfRangeException("skip不能小于1"); |
| | | } |
| | | for (int y = limitRectangle.Start.Y; y <= limitRectangle.End.Y; y += ySkip) |
| | | { |
| | | //超出高度 |
| | | if ((limitRectangle.End.Y - y + 1) < colorArray.Size.Height) |
| | | { |
| | | return false; |
| | | } |
| | | for (int x = limitRectangle.Start.X; x <= limitRectangle.End.X; x += xSkip) |
| | | { |
| | | //超出宽度 |
| | | if ((limitRectangle.End.X - x + 1) < colorArray.Size.Width) |
| | | { |
| | | break; |
| | | } |
| | | |
| | | if (colorArray.Compare(image.Data, x, y)) |
| | | { |
| | | position = new ZTRectangle(x, y, x + colorArray.Size.Width - 1, y + colorArray.Size.Height - 1); |
| | | if (filter(position)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 查找所有数组方框 |
| | | /// </summary> |
| | | /// <param name="image"></param> |
| | | /// <param name="colorArray"></param> |
| | | /// <param name="limitRectangle"></param> |
| | | /// <param name="xSkip"></param> |
| | | /// <param name="ySkip"></param> |
| | | /// <returns></returns> |
| | | public static List<ZTRectangle> FindColorArray(Image<Rgb, byte> image, ColorArray colorArray, ZTRectangle limitRectangle, Int32 xSkip = 1, Int32 ySkip = 1) |
| | | { |
| | | List<ZTRectangle> rects = new List<ZTRectangle>(); |
| | | |
| | | if (xSkip < 1 || ySkip < 1) |
| | | { |
| | | throw new ArgumentOutOfRangeException("skip不能小于1"); |
| | | } |
| | | for (int y = limitRectangle.Start.Y; y <= limitRectangle.End.Y; y += ySkip) |
| | | { |
| | | //超出高度 |
| | | if ((limitRectangle.End.Y - y + 1) < colorArray.Size.Height) |
| | | { |
| | | break; |
| | | } |
| | | for (int x = limitRectangle.Start.X; x <= limitRectangle.End.X; x += xSkip) |
| | | { |
| | | //超出宽度 |
| | | if ((limitRectangle.End.X - x + 1) < colorArray.Size.Width) |
| | | { |
| | | break; |
| | | } |
| | | |
| | | if (colorArray.Compare(image.Data, x, y)) |
| | | { |
| | | rects.Add(new ZTRectangle(x, y, x + colorArray.Size.Width - 1, y + colorArray.Size.Height - 1)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return rects; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 查找数组 |
| | | /// </summary> |