0

I am working on making a drawing program in Pygame. All features are basically complete except for the ability to save your image. Is there any built in Pygame function that does this, or will I have to find some other way (E.G. taking a screenshot or something).

2 Answers2

3

screen is a Surface object which has method subsurface(Rect) to get part of surface - and this part will be also a Surface object.

And there is function pygame.image.save(surface, filename)


Other method: at start create smaller Surface and draw on this surface (instead of drawing directly on screen) and blit() this surface on screen to display it and save() this surface to file.

You can even use many surfaces and keep them on list to create function Undo. When you use new tool then you duplicate surface and put it on list. When you use Undo then you get last surface from list.

furas
  • 134,197
  • 12
  • 106
  • 148
1

If it's a drawing game, then you'll probably find it very easy to manually make the image.

I know it sounds scary, but it really isn't, especially in python.

You can use PyPng to convert a 2D array into an image, as I assume you already use a 2D array to store the drawing

AccountOren3
  • 73
  • 1
  • 5