Python Forum
PIL PILLOW clear an character area
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIL PILLOW clear an character area
#1
I’m using PIL / PILLOW under Python 3.8 with a 128 x 128 OLED display using LUMA.OLED.

I have created a status line and am displaying Glyphs (Icons) in this area which change based on a status (WiFi Strength, Battery Remaining, etc.).

The problem I am having is with the writing the new Glyph over the old... instead of PIL/Pillow completely over-writing the new Glyph over the old... when the new is written, the old can still be seen under it... so it is “compounding” the Glyphs as they are added.

Is there a setting/property that I am missing for this to properly update the character area? Such that the newest Glyph wins?

Clearing the entire screen is not an option... clearing the area under the Glyph will cause the new glyph to appear as flashing...

To me, PIL/Pillow should do some sort of “BIT AND” at the pixel level (for this memory location) such that the new font clears anything under it (where ever a pixel is false on the new glyph).

I’m new the Python but have 20+ years in Windows dev.

Any help is appreciated.

Thank you,
Chuck
Reply
#2
Here’s some more detail...

black = (255,255,255)
self.draw.text((x,y), text=glyph1, font=font, fill=black) #wifi glyph 5 bars
sleep(3)
self.draw.text((x,y), text=glyph2, font=font, fill=black) #wifi glyph 0 bars

I think my issue is with opacity, but can’t figure it out... basically, glyph1 and glyph2 are identical *except* in the number of bars filled. 5 filled vs. 0 filled.

The 5 bars display first... then after 3 seconds (to simulate WiFi Strength changing) I display the 0 bars... what *should* happen is this location changes to unfiltered bars... instead they stay filled.

This means that glyph1 is not being completely over-written by glyph2 (the black areas of glyph2 are treated as “transparent” rather than “opaque” so, the full bars of glyph1 always show through... which is undesired.

I’ve tried every combination of Alpha channel settings... nothing resolves this the way desired.

As mentioned, this is a mono color OLED display.

***how do I get the black pixels to over-write the white pixels *without* clearing the screen/location (because then the Glyphs looks like it has flashed).

Thank you,
Chuck
Reply
#3
Hi,

You state that black is (255,255,255).
In my RGB book, that is white.
(0,0,0) is black.
You said you also have tried all alpha channels.
In fact the model is ARGB (0,255,255,255) Alpha = 0 means you don't see this pixel.
Have you tried putting all the underlying pixels to (0,x,x,x) ?
x may be anything because you don't show the pixel(opacity zerpo)
Paul
Reply
#4
Hi Paul, thanks for your reply.

My mistake on the black... typo’d the wrong values when posted... I have a white and black specified in the code.

I’ll try your suggestion. I was changing the last byte since the the pillow mode is “RGBA”... if the Alpha channel is first like you suggest, then that may be the whole issue.

Thanks for your reply (I will post my results).

Chuck
Reply
#5
... pretty sure the Alpha is the last position... when I change the first position I get a dithered effect on everything... which suggests to me it’s the “R” position.

So, what was suggested, I already tried. The display of glyph2 (black area) does not over-write the white area of glyph1 that is under it.

Since using transparency to do what I described, thinking it is an issue either in Pillow or LUMA.OLED.

Unless, someone else can chime-in with another suggestion.

Chuck
Reply
#6
Ok very possible. You will find references to both ARGB and RGBA.
The bottom line is that setting A to zero does not seem to work.
Could be some PIL problem.

Where do you get your glyphs from?
We know that e.g. in photography, we only use png, if in photoshop
we want to superpose an image with a transparent BG.

Create your own image as jpg ?

Paul
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [solved] unexpected character after line continuation character paul18fr 4 3,389 Jun-22-2021, 03:22 PM
Last Post: deanhystad
  SyntaxError: unexpected character after line continuation character siteshkumar 2 3,162 Jul-13-2020, 07:05 PM
Last Post: snippsat
  how can i handle "expected a character " type error , when I input no character vivekagrey 2 2,732 Jan-05-2020, 11:50 AM
Last Post: vivekagrey
  Replace changing string including uppercase character with lowercase character silfer 11 6,176 Mar-25-2019, 12:54 PM
Last Post: silfer
  SyntaxError: unexpected character after line continuation character Saka 2 18,547 Sep-26-2017, 09:34 AM
Last Post: Saka

Forum Jump:

User Panel Messages

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