image ssd and nju
This commit is contained in:
parent
465e14c972
commit
dae61e68f2
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
@ -15,6 +15,5 @@ LED = 6
|
||||
RPi.GPIO.setup(LED, RPi.GPIO.OUT)
|
||||
RPi.GPIO.output(LED, 1)
|
||||
|
||||
image_file = Image.open("japan_temple_240x320.jpg")
|
||||
image_file = image_file.convert('RGB')
|
||||
image_file = Image.open("assets/japan_temple_240x320.jpg")
|
||||
lcd_tft.draw_image(0, 0, image_file)
|
||||
|
20
gfxlcd/demos/nju_image.py
Normal file
20
gfxlcd/demos/nju_image.py
Normal file
@ -0,0 +1,20 @@
|
||||
import RPi.GPIO
|
||||
import sys
|
||||
import random
|
||||
sys.path.append("../../")
|
||||
from gfxlcd.driver.nju6450.gpio import GPIO
|
||||
from gfxlcd.driver.nju6450.nju6450 import NJU6450
|
||||
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
||||
|
||||
from PIL import Image
|
||||
|
||||
lcd_nju = NJU6450(122, 32, GPIO())
|
||||
lcd_nju.init()
|
||||
lcd_nju.auto_flush = False
|
||||
|
||||
image_file = Image.open("assets/dsp2017_122_29.png")
|
||||
# lcd_nju.threshold = 50
|
||||
# lcd_nju.transparency_color = [110, 57]
|
||||
lcd_nju.draw_image(0, 0, image_file)
|
||||
|
||||
lcd_nju.flush(True)
|
23
gfxlcd/demos/ssd_image.py
Normal file
23
gfxlcd/demos/ssd_image.py
Normal file
@ -0,0 +1,23 @@
|
||||
import RPi.GPIO
|
||||
import sys
|
||||
sys.path.append("../../")
|
||||
from gfxlcd.driver.ssd1306.spi import SPI
|
||||
from gfxlcd.driver.ssd1306.ssd1306 import SSD1306
|
||||
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
||||
from PIL import Image
|
||||
|
||||
lcd_oled = SSD1306(128, 64, SPI())
|
||||
lcd_oled.init()
|
||||
lcd_oled.auto_flush = False
|
||||
|
||||
image_file = Image.open("assets/dsp2017_101_64.png")
|
||||
|
||||
lcd_oled.threshold = 50
|
||||
|
||||
lcd_oled.threshold = 0
|
||||
# lcd_oled.transparency_color = [110, 57] #110 #[110, 57]
|
||||
# lcd_oled.threshold = 255
|
||||
|
||||
lcd_oled.draw_image(10, 0, image_file)
|
||||
|
||||
lcd_oled.flush(True)
|
@ -113,3 +113,26 @@ class Page(Pixel, metaclass=abc.ABCMeta):
|
||||
def flush(self, force=None):
|
||||
"""flush buffer to the screen"""
|
||||
pass
|
||||
|
||||
def draw_image(self, pos_x, pos_y, image):
|
||||
"""draw a PIL image"""
|
||||
image_file = image.convert('L')
|
||||
width, height = image_file.size
|
||||
offset_x = 0
|
||||
offset_y = 0
|
||||
for stream in list(image_file.getdata()):
|
||||
if stream > self.options['threshold'] and not self._is_transparent(stream):
|
||||
self.draw_pixel(pos_x + offset_x, pos_y + offset_y)
|
||||
offset_x += 1
|
||||
if offset_x > width - 1:
|
||||
offset_x = 0
|
||||
offset_y += 1
|
||||
|
||||
def _is_transparent(self, color):
|
||||
"""check if color is a transparency color"""
|
||||
if type(self.options['transparency_color']) == int and color == self.options['transparency_color']:
|
||||
return True
|
||||
elif type(self.options['transparency_color']) == list and color in self.options['transparency_color']:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
@ -12,6 +12,28 @@ class Pixel(object):
|
||||
self.options['background_color'] = {
|
||||
'R': 0, 'G': 0, 'B': 0,
|
||||
}
|
||||
self.options['threshold'] = 50
|
||||
self.options['transparency_color'] = None
|
||||
|
||||
@property
|
||||
def threshold(self):
|
||||
"""get threshold for B&W conversion"""
|
||||
return self.options['threshold']
|
||||
|
||||
@threshold.setter
|
||||
def threshold(self, threshold):
|
||||
"""set B&W threshold for conversion """
|
||||
self.options['threshold'] = threshold
|
||||
|
||||
@property
|
||||
def transparency_color(self):
|
||||
"""get transparency color"""
|
||||
return self.options['transparency_color']
|
||||
|
||||
@transparency_color.setter
|
||||
def transparency_color(self, transparency_color):
|
||||
"""set transparency color """
|
||||
self.options['transparency_color'] = transparency_color
|
||||
|
||||
def draw_pixel(self, pos_x, pos_y):
|
||||
"""dummy fuction"""
|
||||
|
Loading…
Reference in New Issue
Block a user