Trevor Fancher
2005-12-30 00:03:07 UTC
Hello,
I am having some problems with the pygame.image.frombuffer function.
I have
also tried pygame.image.fromstring in the same place.
This works if I use cairo.ImageSurface.write_to_png to write to a
file and
then use pygame.image.load to get the image from the file, but I want
a more
effecient way of using pygame and pycairo together.
I posted to this list because I think the error if with pygame, but I
may be
wrong.
Here's the output and the code:
***@zeppelin ~/Desktop $ python test.py
Traceback (most recent call last):
File "test.py", line 24, in ?
image = pygame.image.frombuffer(buf.getvalue(), size,
'ARGB').convert()
ValueError: Buffer length does not equal format and resolution size
***@zeppelin ~/Desktop $ cat test.py
import cairo
import pygame
import StringIO
s = cairo.ImageSurface(cairo.FORMAT_ARGB32, 100, 100)
c = cairo.Context(s)
c.set_line_width(25)
c.set_source_rgba(.1, .2, .35, .5)
c.move_to(0, 0)
c.line_to(100, 100)
c.move_to(0, 100)
c.line_to(100, 0)
c.stroke()
buf = StringIO.StringIO()
s.write_to_png(buf)
pygame.init()
pygame.display.set_mode((120, 120))
screen = pygame.display.get_surface()
size = (s.get_width(), s.get_height())
image = pygame.image.frombuffer(buf.getvalue(), size, 'ARGB').convert()
image.set_colorkey((0, 0, 0))
screen.fill((160, 160, 160))
screen.blit(image, (10, 10))
pygame.display.flip()
Any suggestion would be great.
Thanks,
__
Trevor Fancher
http://fancher.org/
I am having some problems with the pygame.image.frombuffer function.
I have
also tried pygame.image.fromstring in the same place.
This works if I use cairo.ImageSurface.write_to_png to write to a
file and
then use pygame.image.load to get the image from the file, but I want
a more
effecient way of using pygame and pycairo together.
I posted to this list because I think the error if with pygame, but I
may be
wrong.
Here's the output and the code:
***@zeppelin ~/Desktop $ python test.py
Traceback (most recent call last):
File "test.py", line 24, in ?
image = pygame.image.frombuffer(buf.getvalue(), size,
'ARGB').convert()
ValueError: Buffer length does not equal format and resolution size
***@zeppelin ~/Desktop $ cat test.py
import cairo
import pygame
import StringIO
s = cairo.ImageSurface(cairo.FORMAT_ARGB32, 100, 100)
c = cairo.Context(s)
c.set_line_width(25)
c.set_source_rgba(.1, .2, .35, .5)
c.move_to(0, 0)
c.line_to(100, 100)
c.move_to(0, 100)
c.line_to(100, 0)
c.stroke()
buf = StringIO.StringIO()
s.write_to_png(buf)
pygame.init()
pygame.display.set_mode((120, 120))
screen = pygame.display.get_surface()
size = (s.get_width(), s.get_height())
image = pygame.image.frombuffer(buf.getvalue(), size, 'ARGB').convert()
image.set_colorkey((0, 0, 0))
screen.fill((160, 160, 160))
screen.blit(image, (10, 10))
pygame.display.flip()
Any suggestion would be great.
Thanks,
__
Trevor Fancher
http://fancher.org/