Jump to content

  • Log In with Google      Sign In   
  • Create Account

Pygame Image Problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 shadowgamesco   Members   -  Reputation: 326

Like
0Likes
Like

Posted 25 August 2012 - 10:19 AM

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:

Posted Image

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

Posted Image

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!

Sponsor:

#2 Servant of the Lord   Crossbones+   -  Reputation: 21022

Like
1Likes
Like

Posted 25 August 2012 - 10:43 AM

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?
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#3 shadowgamesco   Members   -  Reputation: 326

Like
0Likes
Like

Posted 25 August 2012 - 10:55 AM

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! Posted Image And this is how I'm creating my window:
screen = pygame.display.set_mode(resolution)

Edited by breinygames, 25 August 2012 - 10:56 AM.


#4 Esys   Members   -  Reputation: 156

Like
1Likes
Like

Posted 25 August 2012 - 11:04 AM

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().

#5 shadowgamesco   Members   -  Reputation: 326

Like
0Likes
Like

Posted 25 August 2012 - 11:11 AM

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!

#6 Servant of the Lord   Crossbones+   -  Reputation: 21022

Like
1Likes
Like

Posted 25 August 2012 - 11:15 AM

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, 25 August 2012 - 11:18 AM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#7 Steveway   Members   -  Reputation: 302

Like
2Likes
Like

Posted 25 August 2012 - 11:17 AM

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.

#8 shadowgamesco   Members   -  Reputation: 326

Like
0Likes
Like

Posted 25 August 2012 - 11:21 AM

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, 25 August 2012 - 12:01 PM.


#9 Djfix   Members   -  Reputation: 237

Like
0Likes
Like

Posted 26 August 2012 - 09:21 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS