用python编写可执行程序,实现对24位bmp图像的缩放并生成新的文件并保存,如何修改下列代码
import struct
import sys
'''
uint8_t BYTE == B
uint32_t DWORD == I
int32_t LONG == i
uint16_t WORD == H
'''
# format='<HIHHI'
class bf():
Type = 0
Size = 1
Reserved1 = 2
Reserved2 = 3
OffBits = 4
# format='<IiiHHIIiiII'
class bi():
Size = 0
Width = 1
Height = 2
Planes = 3
BitCount = 4
Compression = 5
SizeImage = 6
XPelsPerMeter = 7
YPelsPerMeter = 8
ClrUsed = 9
ClrImportant = 10
# format='<BBB'
class rgbt():
Blue = 0
Green = 1
Red = 2
if __name__ == '__main__':
with open('lol.bmp', 'rb') as f:
bitmapfileheader = struct.unpack('<HIHHI', f.read(14))
bitmapinfoheader = struct.unpack('<IiiHHIIiiII', f.read(40))
if bitmapfileheader[bf.Type] != struct.unpack('<H', b'BM')[0]:
print('Wrong file format!', file=sys.stderr)
sys.exit(2)
print(bitmapfileheader[bf.Size])
print(bitmapinfoheader[bi.Height])
print(bitmapinfoheader[bi.Width])
print('Everything is OK.', file=sys.stdout)
sys.exit(0)