I am trying to make a pygame project which involves some images. In these images some are very similar and there is just a change of colour. So I came up with idea that why not to use only one image and change its corresponding colour using Python from this article.
from PIL import Image
import pygame as pg
img = Image.open("Assets/image.png")
img = img.convert("RGBA")
d = img.getdata()
new_image = []
for item in d:
if item[:3] == (0,0,0):
new_image.append((255,255,255,0))
if item[:3] == (23,186,255):
new_image.append((255,38,49,item[3]))
else:
new_image.append(item)
img.putdata(new_image)
img.save("a.png","PNG")
But in the last two lines of the above code its saving the image and I don't want that!
I want to use it in the Pygame code for displaying and then when the program exits the image is gone. So how can I use a list of RGBA values new _image
to display an image in Pygame.
Any help would be appreciated.