Create image from pixel data?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
esrix
Regular
Posts: 28
Joined: Wed May 28, 2008 11:12 pm
Contact:

Create image from pixel data?

#1 Post by esrix »

I was wondering if there was a way to create an image in RenPy from pixel data already in computer memory? For example, if I were to pass RenPy an array of pixel data from a PyGame surface, could I construct an image from that pixel data and use it for a background in RenPy?

Reason is I've got an idea for a game that I can execute the mechanics with in PyGame, but I'd really like for RenPy to handle the storytelling elements. So I'd like to be able to take a screen capture of the game in PyGame and set it as the background in RenPy--essentially faking the appearance of a seemless transition from gameplay to story events.

User avatar
killdream
Veteran
Posts: 325
Joined: Wed Nov 05, 2008 1:05 pm
Projects: EVūL (WIP), insilo (WIP), Cute Demon Crashers!
Deviantart: robotlolita
Github: robotlolita
Location: World's End (aka Brazil)
Contact:

Re: Create image from pixel data?

#2 Post by killdream »

Hm, you can create a custom displayable and blit the surface.

Code: Select all

init python:

    class PyGameSurface(renpy.Displayable):
        
        def __init__(self, surface):
            renpy.Displayable.__init__(self)
            
            self.surface = surface
            
        # Render the displayable
        def render(self, width, height, st, at):
            r = renpy.Render(width, height)
            # we don't need to render the surface, since... well, it's already a SDL surface =D
            # so, just blit it
            r.blit(self.surface, (0, 0)) 
            return r
            
        # Redraw this at each interact
        def per_interact(self):
            renpy.redraw(self, 0)


esrix
Regular
Posts: 28
Joined: Wed May 28, 2008 11:12 pm
Contact:

Re: Create image from pixel data?

#3 Post by esrix »

Sweet. I'll have to give this a try.

Thanks!

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Create image from pixel data?

#4 Post by PyTom »

You can't store a pygame surface inside a displayable if you want to save the displayable. Just pointing that out.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

esrix
Regular
Posts: 28
Joined: Wed May 28, 2008 11:12 pm
Contact:

Re: Create image from pixel data?

#5 Post by esrix »

PyTom wrote:You can't store a pygame surface inside a displayable if you want to save the displayable. Just pointing that out.
Is there a way to convert an array to a surface that the displayable can use?

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Create image from pixel data?

#6 Post by PyTom »

Is there a way to convert an array to a surface that the displayable can use?
Not that I'm willing to support in Ren'Py.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
killdream
Veteran
Posts: 325
Joined: Wed Nov 05, 2008 1:05 pm
Projects: EVūL (WIP), insilo (WIP), Cute Demon Crashers!
Deviantart: robotlolita
Github: robotlolita
Location: World's End (aka Brazil)
Contact:

Re: Create image from pixel data?

#7 Post by killdream »

I guess you could just save a temporary image in the disk and use im.Image to this, so there wouldn't be any problems with the save/load thing. Not sure if it's the best thing to do anyways, but should work.

esrix
Regular
Posts: 28
Joined: Wed May 28, 2008 11:12 pm
Contact:

Re: Create image from pixel data?

#8 Post by esrix »

killdream wrote:I guess you could just save a temporary image in the disk and use im.Image to this, so there wouldn't be any problems with the save/load thing. Not sure if it's the best thing to do anyways, but should work.
True... Perhaps pygame.image.save will do the trick. I'll take a look at it over the weekend.

Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot]