I'm making a pixel editor / a trash version of ms paint in python with pygame, and I want to save the window (canvas?) as a png or jpg. I've seen pygame.image.save, but that only saves a certain surface as an image, I want to save the entire window.
Give the following a try:
pygame.image.save(window, "screenshot.png")
Use pygame.image.save(), which requires PyGame 1.8 or later. If you give it the base-level window surface, it will indeed save the entire window content.
For example:
pygame.image.save( window, 'surface.png' )
The image type is determined by the filename suffix.
Related
First, I know this is a terrible workflow; it's being enforced on me by my employer's SDL Tridion Docs content management system, which seems to specialize in showing complete contempt for its users.
I need to open a raster image in Gimp, paste in a new image, resize the canvas, save and close. This works fine when the pasted-in image is smaller than the original image, but when the pasted-in image is larger I cannot for the life of me find a function to detect the size of the pasted-in image and expand the canvas to fit; all of the functionality seems to assume that the new image will be smaller. I'm looking for the equivalent of the "resize document to selection" command found in Inkscape.
If you do this manually, see Image>Fit canvas to layers.
If you do it in a script, pdb.gimp_image_resize_to_layers(image) in python, something similar in Script-fu.
IMAGE
when I click file>>save as png...
It will save as png to that penguin. Is it possible?
It is possible but the image must be a tkinter PhotoImage.
The picture of your program suggests that it's not a photoimage. However; google "tkinter PhotoImage" and you will find information on how to build one pixel by pixel or however you want. Once you have a photoimage, saving it is easy:
image.write('some_name.png', format='png')
I am making a game, and I want it to be fullscreen. However, the pygame fullscreen is strange, creating a screen too large. So I referred to this: Pygame FULLSCREEN Display Flag Creates A Game Screen That Is Too Large For The Screen. However, when I followed these instructions
import ctypes
ctypes.windll.user32.SetProcessDPIAware()
true_res = (ctypes.windll.user32.GetSystemMetrics(0), ctypes.windll.user32.GetSystemMetrics(1))
pygame.display.set_mode(true_res,pygame.FULLSCREEN)
from an answer (but instead using pywin32 instead of ctypes, like this: win32api.GetSystemMetric(0)).
I used this, and while it does create a fullscreen, it also creates a black border around my screen and enlarges everything a slight bit, including my cursor. How can I get rid of this black border and get all shapes to normal size? Or is there a better way to create a good fullscreen?
If it helps, I use Windows 10.
Thanks in advance!
I think the problem of enlarging everything arose with the use of ctypes module as because the ctypes module makes use of a function named as GetSystemMetrics() whose work is to get the size of the screen of your system.
And might be the import pygame is loading some dll that is not compatible with a dll that windll needs.
So I suggest either you update the ctype library or pygame library or update both libraries or you can enlarge screen size by providing custom width and height values according to the resolution supported by your system.
Hope this helps !!
Recently, I am working on process dicom imagećI don't know how to change the WWWL of a dicom image. Also, I use dcmtk to convert dicom image to bmp and show it(I didn't use vtk to show the image). I really don't know if that is correct.
I want to know the algorithm which can help me change the dicom image's window width and window level automatically. I didn't find the corresponding algorithm while I was using dcmtk.
thanks and regards.
If you want to specify the values of Window Center and Width (aka VOI transformation or windowing) manually, you can use DicomImage::setWindow() for this purpose. If you want to specify an automatically computed min-max window, you could use DicomImage::setMinMaxWindow().
I am new to Python. I wrote a Python code using turtle module, but when i am trying to save the image, the part of the image that is visible in the screen is only getting saved, the parts that are outside are getting cropped. I am saving using the following command:
turtle.getcanvas().postscript(file = "filename.eps")
I have also tried to resize the turtle screen using turtle.screensize() to make it bigger than the drawn image, but then also the part of the image that was saved was the part visible in the screen only.
Please help,
Try setting the height and width arguments.
turtle.getscreen().getcanvas().postscript(file='outputname.ps', height=10000,
width=10000)