public void CalibrateFromImage(int resolution, Bitmap source, string textInImage)
{
int posXInImage = 0;
// iterate for each letter in the text image
for (int i = 0; i < textInImage.Length && posXInImage < source.Width; i++)
{
char letter = textInImage[i];
if (letter == ' ')
continue;
bool foundLetter = false;
int letterStart = 0;
int letterEnd = 0;
// look for the start pixel of the letter
while (!(foundLetter == true || posXInImage >= source.Width))
{
foundLetter = HasWhiteInVerticalLine(source, posXInImage);
posXInImage++;
}
if (foundLetter)
{
letterStart = posXInImage - 1;
// look for the end of the letter
do
{
posXInImage++;
} while (HasWhiteInVerticalLine(source, posXInImage) && posXInImage < source.Width);
letterEnd = posXInImage;
}
// store the image in the alphabet
if (alphabet[resolution, letter] == null && posXInImage != source.Width)
StoreImageInAlphabet(resolution, letter, source, letterStart, letterEnd);
}
}