Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] image color
#2
Once you've loaded the image as a surface, then you can access that surface's pixels with a PixelArray.  The PixelArray class has a replace method, which replaces all instances of one color with another (so you don't need to check individual pixels yourself).  When you create a PixelArray, it locks the underlying surface until it's garbage collected, so you should delete it when you're done (or use a function and return from it).

http://www.pygame.org/docs/ref/pixelarra...ay.replace

So...
surface = load_image() # ...whatever you're already doing
pixels = PixelArray(surface)
pixels.replace(Color(255, 255, 255, 255), Color(0, 0, 255, 255))
del pixels
Reply


Messages In This Thread
image color - by Zman350x - Feb-14-2017, 04:36 PM
RE: image color - by nilamo - Feb-14-2017, 08:22 PM
RE: image color - by nilamo - Feb-27-2017, 12:01 AM
RE: image color - by Zman350x - Feb-26-2017, 11:50 PM
RE: image color - by Zman350x - Feb-27-2017, 12:09 AM
RE: image color - by nilamo - Feb-28-2017, 06:30 PM
RE: image color - by metulburr - Mar-03-2017, 01:34 AM

Forum Jump:

User Panel Messages

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