3

Suppose I create a blank area in a window and draw some lines in it, how can I save that in a .png or .jpg? Or maybe convert it to an object PIL could understand?

pnodbnda
  • 31
  • 1
  • 2

1 Answers1

6

Answer here: Using Pycairo to generate images dynamically and serve in Django though it only says how to save to .png.

surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 100, 100)
context = cairo.Context(surface)
# Draw something ...

surface.write_to_png('filename')
Community
  • 1
  • 1
pnodbnda
  • 649
  • 2
  • 8
  • 12
  • 1
    From information in the original question your link refers to, it sounds like you could use a `surface.get_data()` call coupled with a PIL `Image.frombuffer()` call to create a PIL image which could then be saved in other formats, such as jpg. – martineau Dec 23 '10 at 04:01