Closed car-lisle closed 1 year ago
Hi, I tested your code and got the same result.
The issue you're getting is because you're sending 198x198 bytes of data (see image.size
) into a 240x320 screen, so it's only filling 51% of the screen, and everything is misaligned.
A simple fix is to call display.set_bounds
before drawing:
image = qr.make_image(fill_color="red", back_color="white")
data = list(image.get_image().getdata())
with RaspberryPi() as rpi:
display = Display(rpi)
display.initialize(rotation=90) # this is needed for your display, I think
display.set_bounds(0, 0, image.size[0], image.size[1]) # restrict the draw region to the image size
display.draw_rgb_bytes(data)
This will correctly draw the QR code in the top-left corner.
If you need to draw on the entire screen again, call display.set_bounds(0, 0, display.base_width, display.base_height)
.
I also tried this:
display.set_bounds((display.base_width - image.size[0]) // 2,
(display.base_height - image.size[1]) // 2,
(display.base_width + img.size[0]) // 2,
(display.base_height + img.size[1]) // 2)
Which centers the QR code quite nicely ;)
THANK YOU SO MUCH!!! I really appreciate your fast response! I have been trying to get this to work for weeks. I am so new to this sort of thing and I tried really hard to search online, but I was getting no results. Thank you once again!!! :)
I played around a little bit with the centering code you provided and it's a tad off-center. I had to reduce the qr code image from 198x198 to 145x145 to get it to display to the screen. I'm not really sure what to alter as everything looks fine (you did guess the rotation correctly! :D)
Ah, an interesting issue - there's a logic bug when using base_width
with a rotated display, I think width and height are swapped!
Try the centering code with the original 198x198 size, but using base_width
instead of base_height
and vice-versa. I'll have to fix this one day :)
Thank you so much, that fixed it! :)
Using the examples from this library, I have been trying to generate qr codes to display on this tft. However, the image is stretched and doesn't end up working. However, when I pass images I donwload online, they work just fine.
Here's the test code I used: st7789v-qr-gen-test.txt
The result: