f = open("20201216xv.bmp", 'rb')
bmp_header_b = f.read(0x36)
print(bmp_header_b)
print('')
bmp_header_s = struct.unpack('<2sI2H4I2H6I', bmp_header_b)
print(bmp_header_s)
print('')
def paint_bgcolor(self, color=0xffffff):
self.rgbData = []
for r in range(self.h):
self.rgbDataRow = []
for c in range(self.w):
self.rgbDataRow.append(color)
self.rgbData.append(self.rgbDataRow)
def paint_line(self, x1, y1, x2, y2, color):
k = (y2 - y1) / (x2 - x1)
for x in range(x1, x2+1):
y = int(k * (x - x1) + y1)
self.rgbData[y][x] = color
def paint_rect(self, x1, y1, w, h, color):
for x in range(x1, x1+w):
for y in range(y1, y1+h):
self.rgbData[y][x] = color
这是我学到的打开与画线,画线是给起始点(x1, y1)和结束点(x2, y2),根据两点间的直线方程y = (y2-y1)/(x2-x1)*(x-x1) + y1,来描点
(学习网址:https://mp.weixin.qq.com/s?__biz=MzIyMjYxNzA4NQ==&mid=2247484635&idx=1&sn=c9a2818cc487eb4d8709103c7a3f6003&chksm=e82b8849df5c015fb17768d20a439e8e9c30d1e45d777f28e89343e13b46169564b25442701e&scene=178&cur_album_id=1337165993377955841#rd)