Jump to content
  • Advertisement
Sign in to follow this  
CBreinholt

Pygame Image Problem

This topic is 2304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been working on the HUDs for my game, more specifically the Health, Mana, and XP bars that will be displayed at the bottom of the screen. So I drew up an image in photoshop for the health bar that looks like this:

Screen+shot+2012-08-25+at+10.03.10+AM.png

But for some reason the in-game image looks like this:

Screen+shot+2012-08-25+at+9.50.17+AM.png

As you can tell it is does not match the correct one, and its a little frustrating because in-game it looks too dull. I'm not sure why Pygame is doing this? I'm using the very standard pygame functions to load and render the image:
pygame.image.load('image_path').convert() and surface.blit(hp_image, (position.x, position.y))

Now that I've noticed it, it's actually doing it to a lot of my images! If anyone knows why, please let me know. Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Are you mistakenly creating the window with a color-depth (or bits per pixel, bytes per pixel) less than 8 bits per color channel?
How do you create your window?

Are you mistakenly altering the transparency/alpha-component of the images?
Change the background color to bright pink and then see if that effects the color of the rendered image - if it does, it probably has some accidental transparency.

Both the images you posted above are from the same computer right? One is the actual image, and the other is an actual screenshot of the actual image as seen in the game?

Share this post


Link to post
Share on other sites

Are you mistakenly creating the window with a color-depth (or bits per pixel, bytes per pixel) less than 8 bits per color channel?
How do you create your window?

Are you mistakenly altering the transparency/alpha-component of the images?
Change the background color to bright pink and then see if that effects the color of the rendered image - if it does, it probably has some accidental transparency.

Both the images you posted above are from the same computer right? One is the actual image, and the other is an actual screenshot of the actual image as seen in the game?


Yes, both images are from the same computer, the brighter image is the actual, the duller one is a screenshot of what pygame is doing. I did change the background color to bright pink to check from any transparency mistakes, that's also not the issue. It does the same thing! sad.png And this is how I'm creating my window:

screen = pygame.display.set_mode(resolution)
Edited by breinygames

Share this post


Link to post
Share on other sites
What image format is the original picture? Have you tried changing that? I've found that bitmap images are affected less by pygame's convert().

Share this post


Link to post
Share on other sites

What image format is the original picture? Have you tried changing that? I've found that bitmap images are affected less by pygame's convert().


The image is .png just like all my other images I've been using. I tried re-saving the image to .jpg, and .bmp with 8, 16, 24 and 32 color depths each. I've tried so many different things! Haha. Nothing is working!

Share this post


Link to post
Share on other sites
Well, I no longer think it's the wrong bit depth, because the pixels of your wrong image are actually being changed to different colors (they gain some blue and green, and lose some red), not just rounded to the next closest bit depth.

Samples: (original colors -> wrong colors)
(218, 0, 0) -> (172, 32, 11)
(179, 0, 0) -> (140, 27, 10)
(0, 0, 0) -> (0, 0, 0)
(38, 0, 0) -> (34, 4, 0)


It really looks like something transparent is being drawn over the images, or that the image is transparent and being drawn over something else. Try eliminating every other draw call except for this image being drawn and the surface being filled a solid non-black color. Try (0, 0, 255) to see if the resulting image spikes in blue. Edited by Servant of the Lord

Share this post


Link to post
Share on other sites
Let me guess. You are using a Mac.
This is a bug in the apple-provided png-loading routines that pygame uses on macs.
AFAIK this has been fixed in current versions of pygame, you should get a newer version for your system.

Share this post


Link to post
Share on other sites

Let me guess. You are using a Mac.
This is a bug in the apple-provided png-loading routines that pygame uses on macs.
AFAIK this has been fixed in current versions of pygame, you should get a newer version for your system.


Yep, I just figured this out. When I open the image back in photoshop instead of opening it using the standard 'Adobe RGB (1998)' color profile, I tried opening it in the 'Apple RGB' color profile and opened the image EXACTLY how it looks in-game. So I guess it has to do with how pygame loads the images on Mac, the problem is I have the most updated version of Pygame. Not sure how to fix it now :/ Edited by breinygames

Share this post


Link to post
Share on other sites
When you initialise the screen variabile do it like this

[source lang="python"]screen = pygame.display.set_mode((ScreenWidth,ScreenHeight),0,32)[/source]
If this doesn't work try to remove the .convert from the image loading function and replace it with convert_alpha (so it retains its transparency).If even that doesn't work make your own image loading function and dump Pygame's

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!