-
Notifications
You must be signed in to change notification settings - Fork 8
/
bit_img.py
41 lines (34 loc) · 793 Bytes
/
bit_img.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
"""
Test bitmap image
"""
import sys
from oled import OLED
from oled import Font
from PIL import Image
from oled import Graphics
# Image to be displayed
bitmap = 'bitmaps/clown.bmp'
bitmap = 'bitmaps/raspberry-pi-logo.bmp'
# Draw image location at x,y
def drawImage(bitmap,x,y):
img = Image.open(bitmap)
w = img.size[0]
h = img.size[1]
try:
for i in range(0, w):
for j in range(0, h):
xy = (i, j)
if img.getpixel(xy):
Graphics.draw_pixel(i+x, j+y, False)
else:
Graphics.draw_pixel(i+x, j+y, True)
except: pass
# Initialize library.
dis = OLED(1)
dis.begin()
# Clear display.
dis.clear()
drawImage(bitmap,35,0)
dis.update()
sys.exit(0)