Discuss / Python / 作业(ok)

作业(ok)

Topic source

I-cpp

#1 Created at ... [Delete] [Delete and Lock User]

import struct, base64

def bmp_info(data):

if len(data) > 30:
    L = struct.unpack('<ccIIIIIIHH', data[:30])
    if L[0] == b'B' and L[1] == b'M':
        return {
            'width': L[6],
            'height': L[7],
            'color': L[9]
        }
    else:
        return '该文件非位图文件'
else:
    return '该文件非位图文件'

bi = bmp_info(bmp_data) print(bi['width']) print(bi['height']) print(bi['color']) print('ok')

测试结果:

28 10 16 ok


  • 1

Reply