private static IEnumerable <ImageSplitterItem> SplitHorizontalNew(ImageSplitterItem lineSplitterItem, int xOrMorePixelsMakesSpace) { var bmp = new NikseBitmap(lineSplitterItem.NikseBitmap); bmp.AddTransparentLineRight(); var parts = new List <ImageSplitterItem>(); int startX = 0; int width = 0; int spacePixels = 0; int subtractSpacePixels = 0; for (int x = 0; x < bmp.Width; x++) { bool right; bool clean; List <Point> points = IsVerticalLineTransparetNew(bmp, x, out right, out clean); if (points != null && clean) { spacePixels++; } if (right && points != null) { int add = FindMaxX(points, x) - x; width += add; subtractSpacePixels = add; } var newStartX = points != null?FindMinX(points, x) : 0; if (points == null) { width++; } else if (width > 0 && newStartX > startX + 1) { var bmp0 = new NikseBitmap(bmp); // remove pixels after current; for (int index = 0; index < points.Count; index++) { var p = points[index]; bmp0.MakeVerticalLinePartTransparent(p.X, p.X + index, p.Y); } width = FindMaxX(points, x) - startX; width--; startX++; var b1 = bmp0.CopyRectangle(new Rectangle(startX, 0, width, bmp.Height)); int addY; b1 = CropTopAndBottom(b1, out addY); var couldBeSpace = false; if (spacePixels >= xOrMorePixelsMakesSpace && parts.Count > 0) { parts.Add(new ImageSplitterItem(" ") { Y = addY + lineSplitterItem.Y }); } else if (xOrMorePixelsMakesSpace > 9 && spacePixels >= xOrMorePixelsMakesSpace - 2 && parts.Count > 0) { couldBeSpace = true; } else if (xOrMorePixelsMakesSpace > 3 && spacePixels >= xOrMorePixelsMakesSpace - 1 && parts.Count > 0) { couldBeSpace = true; } if (b1.Width > 0 && b1.Height > 0) { parts.Add(new ImageSplitterItem(startX + lineSplitterItem.X, addY + lineSplitterItem.Y, b1, couldBeSpace)); //y is what? } // remove pixels before next letter; const int begin = 0; foreach (var p in points) { bmp.MakeVerticalLinePartTransparent(begin, p.X, p.Y); } width = 1; startX = FindMinX(points, x); spacePixels = -subtractSpacePixels; subtractSpacePixels = 0; } else if (clean) { width = 1; startX = newStartX; } } return(parts); }
private static IEnumerable<ImageSplitterItem> SplitHorizontalNew(ImageSplitterItem lineSplitterItem, int xOrMorePixelsMakesSpace) { var bmp = new NikseBitmap(lineSplitterItem.NikseBitmap); bmp.AddTransparentLineRight(); var parts = new List<ImageSplitterItem>(); int startX = 0; int width = 0; int spacePixels = 0; int subtractSpacePixels = 0; for (int x = 0; x < bmp.Width; x++) { bool right; bool clean; List<Point> points = IsVerticalLineTransparetNew(bmp, x, out right, out clean); if (points != null && clean) { spacePixels++; } if (right && points != null) { int add = FindMaxX(points, x) - x; width = width + add; subtractSpacePixels = add; } if (points == null) { width++; } else if (width > 1) { var bmp0 = new NikseBitmap(bmp); // remove pixels after current; int k = 0; foreach (Point p in points) { bmp0.MakeVerticalLinePartTransparent(p.X, p.X + k, p.Y); k++; } width = FindMaxX(points, x) - startX; width++; NikseBitmap b1 = bmp0.CopyRectangle(new Rectangle(startX, 0, width, bmp.Height)); if (spacePixels >= xOrMorePixelsMakesSpace && parts.Count > 0) parts.Add(new ImageSplitterItem(" ")); int addY; b1 = CropTopAndBottom(b1, out addY); parts.Add(new ImageSplitterItem(startX + lineSplitterItem.X, addY + lineSplitterItem.Y, b1)); //y is what? // remove pixels before next letter; int begin = 0; foreach (Point p in points) { bmp.MakeVerticalLinePartTransparent(begin, p.X, p.Y); } width = 1; startX = FindMinX(points, x); spacePixels = -subtractSpacePixels; subtractSpacePixels = 0; } else { width = 1; startX = FindMinX(points, x); } } return parts; }
private static IEnumerable <ImageSplitterItem> SplitHorizontalNew(ImageSplitterItem lineSplitterItem, int xOrMorePixelsMakesSpace) { var bmp = new NikseBitmap(lineSplitterItem.NikseBitmap); bmp.AddTransparentLineRight(); var parts = new List <ImageSplitterItem>(); int startX = 0; int width = 0; int spacePixels = 0; int subtractSpacePixels = 0; for (int x = 0; x < bmp.Width; x++) { bool right; bool clean; List <Point> points = IsVerticalLineTransparetNew(bmp, x, out right, out clean); if (points != null && clean) { spacePixels++; } if (right && points != null) { int add = FindMaxX(points, x) - x; width = width + add; subtractSpacePixels = add; } if (points == null) { width++; } else if (width > 1) { var bmp0 = new NikseBitmap(bmp); // remove pixels after current; int k = 0; foreach (Point p in points) { bmp0.MakeVerticalLinePartTransparent(p.X, p.X + k, p.Y); k++; } width = FindMaxX(points, x) - startX; width++; NikseBitmap b1 = bmp0.CopyRectangle(new Rectangle(startX, 0, width, bmp.Height)); if (spacePixels >= xOrMorePixelsMakesSpace && parts.Count > 0) { parts.Add(new ImageSplitterItem(" ")); } int addY; b1 = CropTopAndBottom(b1, out addY); parts.Add(new ImageSplitterItem(startX + lineSplitterItem.X, addY + lineSplitterItem.Y, b1)); //y is what? // remove pixels before next letter; int begin = 0; foreach (Point p in points) { bmp.MakeVerticalLinePartTransparent(begin, p.X, p.Y); } width = 1; startX = FindMinX(points, x); spacePixels = -subtractSpacePixels; subtractSpacePixels = 0; } else { width = 1; startX = FindMinX(points, x); } } return(parts); }