I want to read binary file (like .bmp or .jpg) and convert each binary data to ascii and do multiplication (like ascii * 2) and convert back to binary format and write to a new file.
I wrote the program as below
filename = input("enter file to read: ")
readfile = filename + ".bmp"
writefilebmp = filename + '1' + ".bmp"
fr = open(readfile,"rb");
fwbmp = open(writefilebmp,"wb");
bytes_read = fr.read(1024)
for b in bytes_read:
print(b,end='')
data = b*2;
fwbmp.write(data)
fr.close()
fwbmp.close()
But i'm getting the below error
TypeError: 'int' does not support the buffer interface
Note: Once i the solution, i will modify the code to skip the bmp or jpeg header
Modified
filename = input("enter file to read: ")
readfile = filename + ".bmp"
writefilebmp = filename + '1' + ".bmp"
fr = open(readfile,"rb");
fwbmp = open(writefilebmp,"wb");
bytes_read = fr.read(20)
for b in bytes_read:
print(b,end='')
data = b*2;
fwbmp.write(bytes(data))
fr.close()
fwbmp.close()