You can't compare bytes to pixels.  You need a conversion factor here.

I've given a detailed review of this code before.