[cairo] API Suggestion
James Mills
prologic at shortcircuit.net.au
Fri Oct 7 22:11:29 PDT 2005
Hi,
I'm not sure if you guys have this planned, but I've been using
pycairo, and it needs an api function that'll make it just that one bit
more usefull and nicer to use. cairo + pycair btw is really really
great :)
I've been trying to use pycairo to draw images and render them directly
using sdl (pygame).
pygame.image has a function called frombuffer, if pycairo's surface or
something had a similar function, perhaps tobuffer, or perhaps the
object itself could be some kind of buffer (I have no idea what I'm on
about here!) then you could easily:
image = pygame.image.frombuffer(ctx)
or something :)
Please find attached ex1.py which I was working on as a test.
Note: the only solution I (and other pygame developers) could find was
to use a temporary file, however this is slow :)
cheers
James
--
--
-"Problems are Solved by Method"
-
- James Mills <prologic at shortcircuit.net.au>
- HomePage: http://shortcircuit.net.au/~prologic/
- Phone: +61732166379
- Mobile: +61404270962
- Skype: therealprologic
- MSN: prologic at shortcircuit.net.au
- ICQ: 98888663
- IRC: irc://shortcircuit.net.au#se
Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
-------------- next part --------------
#!/usr/bin/env python
import cairo
import pygame
from pygame.locals import *
WIDTH = 400
HEIGHT = 400
def main():
pygame.init()
screen = pygame.display.set_mode((640,480))
pygame.display.set_caption("PyCairo Example")
screen.fill((255, 255, 255, 255))
pygame.display.update()
pygame.mouse.set_visible(1)
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context(surface)
ctx.set_line_width(1)
ctx.move_to(200, 100)
ctx.line_to(300, 300)
ctx.rel_line_to(-200, 0)
ctx.close_path()
ctx.stroke()
#surface.write_to_png("triangle.png")
#image = pygame.image.load(surface.write_to_png())
import tempfile
f = tempfile.NamedTemporaryFile()
surface.write_to_png(f.name)
image = pygame.image.load(f.name)
f.close()
screen.blit(image, [0, 0])
pygame.display.update()
done = False
while not done:
for event in pygame.event.get():
if event.type is QUIT:
done = True
if __name__ == "__main__":
main()
More information about the cairo
mailing list