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

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



A very quick way of doing it is just to use transform.threshold [0].
Something along the lines of:

yellow = (255, 255, 0) # or whatever yellow color you want
threshold = (10, 10, 10) # or whatever threshold works
blue = (0, 0, 255)
pygame.transform.threshold(destsurface, surface, yellow, thresh, blue,
1, None, True)

[0] http://www.pygame.org/docs/ref/transform.html#pygame.transform.threshold

On Sun, Mar 14, 2010 at 5:34 PM, Ian Mallett <geometrian@xxxxxxxxx> wrote:
> Hi,
>
> You could replace the pixels of the given color using surfarray or
> pixelarray before blitting.  You could also make it an 8 bit surface and
> adjust the palette.  You could also just do a manual loop though all the
> pixels with .get_at(), .set_at().  Personally, I'd go with surfarray or
> pixelarray--it's fast, and doesn't suffer from bit-depth loss like
> palettes.
>
> There may be better ways, contingent on what exactly you're doing.  You may
> be able to adjust your algorithm so that this situation doesn't happen.  A
> more complete description of what you're doing?
>
> Ian
>