/// <summary> /// Finds a left or a right margin depending on the second argument /// </summary> private double FindMargin(Bitmap image, bool right, bool useFullImage) { Bitmap downscaled = useFullImage ? BitmapUtils.Resize(image, 80, 80) : image; int pixelMargin = downscaled.Width - 1; bool found = false; int iStartValue = right ? downscaled.Width - 1 : 0; int increment = right ? -1 : 1; int iEndValue = right ? -1 : downscaled.Width; int jStartValue = useFullImage ? 0 : (int)(coreRegionTop * Font.pixelsPerCmV); int jEndValue = useFullImage ? downscaled.Height : (int)(coreRegionBottom * Font.pixelsPerCmV); for (int i = iStartValue; i != iEndValue; i += increment) { for (int j = jStartValue; j < jEndValue; j++) { if (IsPartOfTheLetter(downscaled, i, j)) { pixelMargin = i; found = true; goto loopend; } } } loopend: //image.SetPixel(pixelMargin * Font.imagePixelW / downscaled.Width, 220, Color.Red); if (!found) { return(-1); } double cmMargin = (pixelMargin * Font.imagePixelW / downscaled.Width) * Font.imageCmW / Font.imagePixelW; return(cmMargin); }
private void PrepareData() { originalForm = BitmapUtils.LoadBitmap(path); Bitmap smallForm = BitmapUtils.Resize(originalForm, smallImageWidth, originalForm.Height * smallImageWidth / originalForm.Width); BWThreshold = BitmapUtils.GetMinMaxMiddleColorThreshold(smallForm); CreateSmallExpandedBW(smallForm); largeForm = BitmapUtils.Resize(originalForm, largeImageWidth, originalForm.Height * largeImageWidth / originalForm.Width); }