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?
Asked
Active
Viewed 3,568 times
1 Answers
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')
-
1From 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