Answer the question
In order to leave comments, you need to log in
Rewriting code from python to c. One line is not clear at all, how?
It is not clear how to write the line byte |= bit << bit_i in C
Here is the full code:
f = open(outfn, 'wb')
f.write(struct.pack('HH', H, W))
for j in range(H):
for i in range(0, W, 8):
byte = 0
for bit_i in range(8):
try:
bit = im.getpixel((i + bit_i, j)) < 255
except:
bit = False
# sys.stdout.write(' X'[bit])
byte |= bit << bit_i
f.write(struct.pack('B', byte))
print 'wrote', outfn
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question