import struct,os
try:
with open(os.sep.join(('E:','test.bmp')),'rb') as file1:
a=struct.unpack('<ccIIIIIIhh',file1.read()[:30])
if a[0]+a[1]==b'BM':
print('图片是位图文件,大小为:%.2fkb,尺寸为%dmm*%dmm,像素为:%dpx*%dpx,颜色数为:%d'%(a[2]/1024,a[4]*3,a[5]*3,a[6],a[7],a[9]))
else:
print('本文件不是位图文件')
except:
print('打开文件错误,请检查文件是否存在!')
儒生脱尘