Discuss / Python / 作业

作业

Topic source

泛色海岸

#1 Created at ... [Delete] [Delete and Lock User]
def checkbmp(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        for i in args:
            if not isinstance(i, bytes):
                raise ValueError('输入bytes型数据')
        return func(*args, **kwargs)
    return wrapper
@checkbmp
def bmp_info(data):

    data_std = data[:30]

    info = struct.unpack('<ccIIIIIIHH', data_std)
    bmp = {}

    bmp['size'] = info[2]   # 一个4字节整数:表示位图大小
    bmp['offset'] = info[3] # 实际图像的偏移量
    bmp['width'] = info[-4] # 一个4字节整数:图像宽度
    bmp['height'] = info[-3]#一个4字节整数:图像高度
    bmp['color'] = info[-1] #一个2字节整数:颜色数

    return bmp

  • 1

Reply