Create image from pixel data?
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.
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.
Create image from pixel data?
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.
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.
- 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?
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)
Re: Create image from pixel data?
Sweet. I'll have to give this a try.
Thanks!
Thanks!
- 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?
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(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: Create image from pixel data?
Is there a way to convert an array to a surface that the displayable can use?PyTom wrote:You can't store a pygame surface inside a displayable if you want to save the displayable. Just pointing that out.
- 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?
Not that I'm willing to support in Ren'Py.Is there a way to convert an array to a surface that the displayable can use?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
- 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?
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.
Re: Create image from pixel data?
True... Perhaps pygame.image.save will do the trick. I'll take a look at it over the weekend.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.
Who is online
Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot]