transparent image on ili
demo file
This commit is contained in:
parent
dae61e68f2
commit
dbeae3385a
BIN
gfxlcd/demos/assets/numbers.jpg
Normal file
BIN
gfxlcd/demos/assets/numbers.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.9 KiB |
@ -17,3 +17,7 @@ RPi.GPIO.output(LED, 1)
|
||||
|
||||
image_file = Image.open("assets/japan_temple_240x320.jpg")
|
||||
lcd_tft.draw_image(0, 0, image_file)
|
||||
|
||||
numbers_image = Image.open("assets/dsp2017_101_64.png")
|
||||
lcd_tft.transparency_color = (0, 0, 0)
|
||||
lcd_tft.draw_image(10, 10, numbers_image)
|
@ -132,6 +132,36 @@ class Area(Pixel):
|
||||
pos_x + width - 1,
|
||||
pos_y + height - 1
|
||||
)
|
||||
for r, g, b in list(image_file.getdata()):
|
||||
self.color = (r, g, b)
|
||||
row = 0
|
||||
col = 0
|
||||
area = None
|
||||
temporary_area = None
|
||||
for red, green, blue in list(image_file.getdata()):
|
||||
if self._is_transparent((red, green, blue)):
|
||||
area = (pos_x, pos_y + row + 1, pos_x + width - 1, pos_y + height - 1)
|
||||
temporary_area = (pos_x + col + 1, pos_y + row, pos_x + width - 1, pos_y + row)
|
||||
else:
|
||||
if temporary_area is not None:
|
||||
self._set_area(*temporary_area)
|
||||
temporary_area = None
|
||||
self.color = (red, green, blue)
|
||||
self.driver.data(self._converted_color(), None)
|
||||
|
||||
col += 1
|
||||
if col > width - 1:
|
||||
col = 0
|
||||
row += 1
|
||||
if area is not None:
|
||||
self._set_area(*area)
|
||||
area = None
|
||||
|
||||
def _is_transparent(self, color):
|
||||
"""check if color is a transparency color"""
|
||||
if self.options['transparency_color'] is None:
|
||||
return False
|
||||
elif type(self.options['transparency_color'][0]) == int and color == self.options['transparency_color']:
|
||||
return True
|
||||
elif type(self.options['transparency_color'][0]) == list and color in self.options['transparency_color']:
|
||||
return True
|
||||
|
||||
return False
|
Loading…
Reference in New Issue
Block a user