I need to read a bitmap file (.bmp) and split the binary data into an array of bytes, which I can then restore to the original file. In the end, I will modify part of each byte to store data, and then read it to return data.
More details
I am currently using
file = open ("example.bmp", "rb")
data = file.read ()
file.close ()
to get the data. However, it is rather slow and inefficient. Then I want to split it into a byte array and change the last bit to 0 for each bit that is not part of the metadata (I will use if to subtract 1 from each odd byte). Then I re-merge the data and save it in a new image file with the following code:
file = open ("example2.bmp", "wb")
file.write (data)
file.close ()
although I suspect this may not be optimal either.
I need to know how to split a lot of binary data into bytes.
source share