Hmmm, a higher horizontal resolution means a different data type (here, uint32_t instead of uint8_t), which is moderately more annoying to handle...
But other than that, yeah, that works.
Code:
row="........########................"
row.replace('.', '0')
row.replace('#', '1')
hex = '%0*X' % ((len(row) + 3) // 4, int(row, 2))
00FF0000