utilise a custom rgba to rgb image type converter. One that is aware of brightness(a)
This commit is contained in:
parent
895f87aecb
commit
415f2f9987
1 changed files with 22 additions and 2 deletions
|
@ -15,15 +15,35 @@ matrix = RGBMatrix(options = options)
|
||||||
|
|
||||||
|
|
||||||
# Load image and make sure it fits our screen.
|
# Load image and make sure it fits our screen.
|
||||||
|
def pure_pil_alpha_to_color_v2(image, color=(0, 0, 0)):
|
||||||
|
"""Alpha composite an RGBA Image with a specified color.
|
||||||
|
|
||||||
|
Simpler, faster version than the solutions above.
|
||||||
|
|
||||||
|
Source: http://stackoverflow.com/a/9459208/284318
|
||||||
|
|
||||||
|
Keyword Arguments:
|
||||||
|
image -- PIL RGBA Image object
|
||||||
|
color -- Tuple r, g, b (default 255, 255, 255)
|
||||||
|
|
||||||
|
"""
|
||||||
|
image.load() # needed for split()
|
||||||
|
background = Image.new('RGB', image.size, color)
|
||||||
|
background.paste(image, mask=image.split()[3]) # 3 is the alpha channel
|
||||||
|
return background
|
||||||
|
|
||||||
image = Image.open("../testImg.bmp")
|
image = Image.open("../testImg.bmp")
|
||||||
image.thumbnail((matrix.width, matrix.height), Image.ANTIALIAS)
|
RGBImage = pure_pil_alpha_to_color_v2(image.thumbnail((128,62), Image.ANTIALIAS))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# offscreen canvas that can be written to which can then be set to the matrix async
|
# offscreen canvas that can be written to which can then be set to the matrix async
|
||||||
offscreen_canvas = matrix.CreateFrameCanvas()
|
offscreen_canvas = matrix.CreateFrameCanvas()
|
||||||
offscreen_canvas.brightness = 50
|
offscreen_canvas.brightness = 50
|
||||||
offscreen__text_canvas = matrix.CreateFrameCanvas()
|
offscreen__text_canvas = matrix.CreateFrameCanvas()
|
||||||
offscreen__text_canvas.brightness = 50
|
offscreen__text_canvas.brightness = 50
|
||||||
offscreen__text_canvas.SetImage(image.convert('RGB'))
|
offscreen__text_canvas.SetImage(RGBImage)
|
||||||
|
|
||||||
|
|
||||||
def updateScreen():
|
def updateScreen():
|
||||||
|
|
Loading…
Reference in a new issue