Is there a way to make a temporary "image" with Pyglet? (Something akin to LÖVE's Canvas).
Basically, I want to have an object that I could blit stuff like sprites and text to, and then blit this temporary image to the window.
I tried creating an image with pyglet.image.create(), but apparently it procures an ImageData which you can't blit to.
Thank you very much for your attention.
Checkout AbstractImage. It has all the methods I think you want - creating an image offline, blitting stuff to it:
myimage.blit_into('sprite1',x,y,z)
myimage.blit_into('sprite2',x+20,y,z)
and then blitting it to the active frame:
myimage.blit(x,y[,z])
etc.
Related
How to delete drawn objects with OpenCV in Python ?
I draw objects on click (cv2.rectangle, cv2.circle) ...
Then I would like to delete only drawn objects.
I know that i need to make a layer in behind of the real image and to draw on another one.
But I do not know how to implement this in code.
Have a method or something that when it's executed, will replace the image with stuff drawn on it with an original unaltered image. It's best to create a clone of your original image to draw on.
When using python and pygame: after loading the screen with the background image and blitting new objects (Text, circles, rectangles, etc.), is there a way to save the modified screen so as to be recalled later in the program? Specifically, I am setting the background and blitting new objects and would like to save the screen image with all of the blits in intact so it can be used later in the program as a new background upon which sprites can be manipulated. Any suggestions welcomed!
Blitting works both ways, meaning you can blit something onto the display screen, but you can also blit the screen onto another surface. So simply make a new surface the same size of your display surface and blit the screen onto that surface for later use.
found a solution and it works better than I expected:
after blitted my raw background onto my surface and then adding numerous circles, rectangles and text to make an image with multiple dial, gauges and labels I ran the following:
pygame.display.update()
window = pygame.display.set_mode((800,480),0,32)
pygame.image.save(TFT,"screen_update.jpg")
the new image is saved to disk(XDcard on my RPi2) as "screen_update.jpg"
then I simply change the name to "ANAL_update.jpg" and use that as the background on my next program run. I commented out all of the code used to create the rectangles, circles and labels and it works. I will add an selectable "update" routine to the program and move all of extra drawing and labelling to that routine to be used when I wish to change the layout of he background. I like the fact that the program creates a new updated file that just needs to be renamed for use and for copying the background to other machines.
note: This is working on my RaspberryPi 2B with HDMI output to a 42" HD tv for development, but it is intended to run on an RPi3B with he official RPi 7 inch TFT display. Thanks to all of you that responded and to the others who left pertinent code for previous questions similar to mine.
i want to load an image for 5 seconds and then delete it from the display surface without overwriting it.
I load my image with this function:
pygame.image.load('image.png')
is there a function that undo this in python?
No, once you change a Surface, it remains change.
An easy solution is to just create a copy of the target Surface before you change it (using .copy()) and, if the Surface in question is the root Surface, simply blit the copy back onto it.
How can I add image to my Turtle Screen using turtle graphics?
whenever I use the function addshape I keep getting errors.
does turtle graphics got any other way loading/importing images?
for example:
import turtle
screen = turtle.Screen()
image = r"C:\Users\myUser\Desktop\Python\rocketship.png"
screen.addshape(image)
turtle.shape(image)
The turtle module does have support for images, but only GIF images, not PNG or any other format. As the docs for addshape say:
name is the name of a gif-file and shape is None: Install the corresponding image shape.
And if you look at the source, they're serious about "gif-file": the way it decides whether you're trying to add an image or a polygon is by calling data.lower().endswith(".gif"), which obviously won't work for .png files.
And, even if you fix that, it will still only be able to handle the file formats that Tkinter supports out of the box, which includes some extra things like PPM/PGM/PBM, but still not PNG. If you want to support PNG files, you'll want to install Pillow as well.
At this point, you're getting beyond what people usually do with turtle. That might be worth pursuing (you'll learn a lot by doing so), but it may be simpler to use an image-converting program to convert the .png file to a .gif file so it will work with your existing code.
You can only use gif files with Python Turtle. Take any picture and convert/resize for free at ezgif.com.
Background:
win = turtle.Screen()
win.bgpic('background.gif')
Using shapes:
win.register_shape('pic1.gif')
sprite = turtle.Turtle()
sprite.shape('pic1.gif')
Example game:
https://www.youtube.com/watch?v=q49Xyo0LYDs
I've been using pygame to make a game recently, and have ran into a little problem...
Basically, I would like to be able to stretch the whole image that is on the screen (all the things that I have blitted to it) into the resolution which the user has resized the window to. I've searched a lot on the documentation for pygame and on stack overflow and I can't seem to find an answer... Is it even possible? The source code for my game is pretty big atm, if anyone needs it I'll be willing to post it. Sorry if I made my question a little unclear :)
Blit everything to a separate surface (not directly to the screen), let's call it main_surface. Then blit the main_surface to the screen.
Call pygame.transform.scale(main_surface, (width, height) with the new width and height that you get from the VIDEORESIZE event to scale the main_surface and everything in it to the new window dimensions.