def show_image(image): """ Renders an image to the display. Handles splitting colours. """ image = image.convert("RGB") # Create red & black images of the right size black_image = Image.new("1", IMAGE_SIZE, 1) red_image = Image.new("1", IMAGE_SIZE, 1) # Copy pixels into them for x in range(IMAGE_SIZE[0]): for y in range(IMAGE_SIZE[1]): pixel = image.getpixel((x, y)) if pixel[1] < 100: if pixel[0] > 125: # Red red_image.putpixel((x, y), 0) else: # Black black_image.putpixel((x, y), 0) # Send to the display epd = epd5in83bc.EPD() epd.init() # epd.Clear() try: epd.display(epd.getbuffer(black_image), epd.getbuffer(red_image)) time.sleep(2) finally: epd.sleep()
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic') libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib') if os.path.exists(libdir): sys.path.append(libdir) import logging from waveshare_epd import epd5in83bc import time from PIL import Image,ImageDraw,ImageFont logging.basicConfig(level=logging.DEBUG) try: logging.info("epd5in83bc Demo") epd = epd5in83bc.EPD() logging.info("init and Clear") epd.init() epd.Clear() time.sleep(1) # Drawing on the image logging.info("Drawing") font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24) font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18) # Drawing on the Horizontal image logging.info("1.Drawing on the Horizontal image...") HBlackimage = Image.new('1', (epd.width, epd.height), 255) # 298*126 HRYimage = Image.new('1', (epd.width, epd.height), 255) # 298*126 ryimage: red or yellow image drawblack = ImageDraw.Draw(HBlackimage)