[Image-SIG] unable to make PIL work with cairo
wecing
w3cing at gmail.com
Sun Jan 9 11:37:25 CET 2011
I wrote my code like this:
> def video_observer(self, f):
>
> img = Image.frombuffer('RGB', (self._width, self._height), f.data,
>> \
>
> 'raw', 'RGB', 0, 1)
>
>
>> img = img.resize((self.nwidth, self.nheight))
>
> img.save('%d.jpg' % self.cnt, 'JPEG') # debug! :-P
>
>
>
> imgd = img.tostring('raw', 'RGBA', 0, 1)
>
> a = array.array('B', imgd)
>
>
>> surface = cairo.ImageSurface.create_for_data(a,
>> cairo.FORMAT_ARGB32, \
>
> self.nwidth, self.nheight, self.nwidth * 4) # self.nwidth * 4
>
>
>> surface.write_to_png('%d.png' % self.cnt)
>
>
>> self.context.set_source_surface(surface, 0, 0)
>
> self.context.paint()
>
>
Output of img.save() is perfectly correct, but...
> File "main.py", line 98, in video_observer
imgd = img.tostring('raw', 'RGBA', 0, 1)
File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 535, in
> tostring
e = _getencoder(self.mode, encoder_name, args)
File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 399, in
> _getencoder
return apply(encoder, (mode,) + args + extra)
SystemError: unknown raw mode
Why?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20110109/bbc6cc87/attachment.html>
More information about the Image-SIG
mailing list