[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] How to replace a color in an image?



Hi Ian. I'm just trying to replace every instance of one color with another color, before I render the map_image. Right now I'm using PixelArray to do this, like so:

screen = pygame.display.set_mode(SCREEN_SIZE)
map_image = pygame.image.load('map_image.png').convert_alpha()
image_pixel_array = pygame.PixelArray(map_image)
image_pixel_array.replace(YELLOW, BLUE)

And then in my main game loop, I render with:
screen.blit(map_image, (0, 0))
pygame.display.update()


I've looked in the documentation, but I still don't get exactly how to use transform.threshold... could you should me exactly how to use it, instead of PixelArray, in the above example? Thanks!





On Thu, Mar 18, 2010 at 3:35 AM, Ian Mallett <geometrian@xxxxxxxxx> wrote:
On Mon, Mar 15, 2010 at 5:35 PM, Jordan - Necessary Games <jordan@xxxxxxxxxxxxxxxxxx> wrote:
Thanks very much for both replies! Pixelarray looks like it will do exactly what I need at the moment.
Actually, I think I may have to recommend the .transform function.  PyGame changes . . .

map_image = pygame.image.load('map_image.png').convert_alpha()

#pygame.transform.threshold(DestSurface, Surface, color, threshold = (0,0,0,0), \
#diff_color = (0,0,0,0), change_return = 1, Surface = None, inverse = False): return num_threshold_pixels

What specifically are you trying to do to to map_image?