from PIL import Image STATIC = 1 ANIMATION = 2 startx, starty = 16,25 image_on = Image.open("file_on_m.bmp") image_off = Image.open("file_off_m.bmp") # im = image.convert(mode='') # im_pixels = im.load() # # access pixels via [x, y] # for col in range(im.size[0]): # for row in range(im.size[1]): # brightness = sum(im_pixels[col, row]) # if brightness < 255*2: # im_pixels[col, row] = (0, 0, 0) # else: # im_pixels[col, row] = (255,255,255) # im.save('file_on_m.bmp') def bmp_to_bitmap_fn(im): def fn(img): x = [xc if sum(im.getpixel((xc,yc))) == 0 else None for xc in range(im.size[0]) for yc in range(im.size[1])] y = [yc if sum(im.getpixel((xc,yc))) == 0 else None for xc in range(im.size[0]) for yc in range(im.size[1])] x = list(filter(lambda x: x!=None, x)) y = list(filter(lambda y: y!=None, y)) xmin, xmax = min(x), max(x) ymin, ymax = min(y), max(y) # print(xmin, xmax, ymin, ymax) xsize = (xmax-xmin) ysize = (ymax-ymin) print(len(img)) for y in range(ysize): for x in range(0,xsize): # print(xmin+x+bit, ymin+y) if im.size[0] >= x and sum(im.getpixel((xmin+x,ymin+y))) == 0: # print( im.size[0], x,x+bit, (xmin+x+bit,ymin+y)) pos = ((y * xsize) + x) // 8 bit = ((y * xsize) + x) % 8 print(pos, 1<