Discuss / Python / 作业

作业

Topic source

皇甫Yuri

#1 Created at ... [Delete] [Delete and Lock User]
from collections import namedtuple

BMPInfo = namedtuple('BMPInfo',('ch1','ch2','size','reserved','offset','headerbits','width','height','num','colornum'))

def bmp_info(data):
    info = BMPInfo(*struct.unpack('<ccIIIIIIHH', data[:30]))
    if info.ch1 == b'B' and (info.ch2 == b'M' or b.ch2 == b'A'):
        return {
            'width': info.width,
            'height': info.height,
            'color': info.colornum
        }
    return None

皇甫Yuri

#2 Created at ... [Delete] [Delete and Lock User]
from collections import namedtuple

BMPInfo = namedtuple('BMPInfo',('ch1','ch2','size','reserved','offset','headerbits','width','height','num','colornum'))

def bmp_info(data):
    info = BMPInfo(*struct.unpack('<ccIIIIIIHH', data[:30]))
    if info.ch1 == b'B' and (info.ch2 == b'M' or info.ch2 == b'A'):
        return {
            'width': info.width,
            'height': info.height,
            'color': info.colornum
        }
    return None

  • 1

Reply