Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

[PYGAME] Problem with headless window

Florea_StefanFlorea_Stefan Posts: 1Member
Hello,
I am trying to make an application that will run a simulation on a headless server. In short, it does the following:

1. load an image from the database
2. display a text as an overlay on top of the image
3. capture the 'screen' and save the image back to the database

The problem is that when saving the image back to the database I loose a lot of colors! But only when running the simulation headless.

Here is the part where I initialize pygame and tell to create a headless application:

[code]os.environ["SDL_VIDEODRIVER"] = "dummy"
pygame.init()
pygame.display.set_mode((1,1))[/code]


Here is the part where I create the 'screen' buffer

[code]GS._SCREEN = pygame.Surface((640, 480)).convert()[/code]



The main algorithm is something like this:
[code]def MainLoop():
GS._SCREEN.fill([255,0,0]) # clear the buffer

GS._SCREEN.blit(sprite, (0,0)) # display something on the buffer
pygame.image.save(GS._SCREEN, "path/to/directory") #save the image back in the database
pygame.display.flip()
[/code]


http://www.box.net/f...2/1/f_968101145 <- This is how the image should look like

http://www.box.net/f...2/1/f_968100995 <- This is how it actually looks after it is saved. As you can see it has less colors.

REMARK: if am not using a headless window, the image is saved CORRECTLY!

Here is the whole code:

[code]import pygame
import os

# initialize headless pygame
os.environ["SDL_VIDEODRIVER"] = "dummy"
pygame.init()
pygame.display.set_mode((1,1))

# create image buffer
SCREEN = pygame.Surface((640, 480)).convert()


# load a simple image
sprite = pygame.image.load("Assets/Sprite/spriteTest.jpg").convert()

# display it on the buffer
SCREEN.blit(sprite, (0,0))

# save the buffer
pygame.image.save(SCREEN, "Assets/Output/spriteResult.jpg")[/code]



Regards,
Florea Stefan.

Comments

  • 6307418529y6307418529y Posts: 1Member
    import pygame
    import os

    # initialize headless pygame
    os.environ["SDL_VIDEODRIVER"] = "dummy"
    pygame.init()
    pygame.display.set_mode((1,1))

    # create image buffer
    SCREEN = pygame.Surface((640, 480)).convert()


    # load a simple image
    sprite = pygame.image.load("Assets/Sprite/spriteTest.jpg").convert()

    # display it on the buffer
    SCREEN.blit(sprite, (0,0))

    # save the buffer
    pygame.image.save(SCREEN, "Assets/Output/spriteResult.jpg")
Sign In or Register to comment.