Python Forum
python script for gfx hat (LCD for raspberry)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python script for gfx hat (LCD for raspberry)
#11
Hi,

reading through the documentation, I guess that lcd.set_pixel() expects an 8-bit value for pixel. When you read a JPG image, you get at least a tuple of three 8-bit values like (128, 255, 10) for RGB. Thus, I guess you need to convert your image into one of gray shades first. I also guess that Pillow has a method for that. Just dig yourself through the documentation.

Regards, noisefloor
Reply
#12
(Jul-04-2019, 05:22 PM)noisefloor Wrote: Hi,

reading through the documentation, I guess that lcd.set_pixel() expects an 8-bit value for pixel. When you read a JPG image, you get at least a tuple of three 8-bit values like (128, 255, 10) for RGB. Thus, I guess you need to convert your image into one of gray shades first. I also guess that Pillow has a method for that. Just dig yourself through the documentation.

Regards, noisefloor

Hy thank you

my new script :

#!/usr/bin/env python
import time
from gfxhat import lcd, backlight, fonts
from PIL import Image, ImageFont, ImageDraw

print("""Message de demarrage""")

backlight.set_all(240,240,240)
backlight.show()

lcd.clear()

image = Image.open("/tmp/aa.jpg")

for x in range(124):
    for y in range(64):
		pixel = int(image.getpixel((x, y))[0])
		print(pixel)
		lcd.set_pixel(x, y, pixel)

lcd.show()
thanks to you i have understand the mechanism,
and i want to thank you a lot.
Reply
#13
Hi,

well, you'll get something displayed indeed - but you may get unexpected results. You still use a colored picture, but only use the 8bit representing the R (red) channel assuming the JPG is stored with RGB value. So if by incident your JPG has on all pixels on red, you won't see anything.

I still highly recommend to convert your image object into one having grey shades only, where each pixel is represent by a single 8bit value.

Regards, noisefloor
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Re-write BASH script to Python script popi75 5 2,409 Apr-30-2021, 03:52 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020