@ Karlos
I don't see why you need to scan vertically, you should be able to get x and y values by scanning horizontally.
Also by scanning vertically you'll get a potentially massive speed hit as reading from RAM non-sequentially is very slow.
Assuming the index is in the top left:
Scan across, and when you hit the first correct pixel record xMin, xMax, yMin and yMax.
Scan the next line, if the pixel's x value is lower and it's touching the xMin you can record it as a new xMin, and increment yMax while there are other releant pixels touching you set a higher xMax.
--
That should work for solid areas but you'll need to implement something to track "previous pixels which were touching" if you want to capture non-solid objects.
That useful?
EDIT: I was suggesting an area fill for an alternative but this will not work on irregular shapes (i.e. an S).