1

I'm currently working on a GUI for a telescope.
I've got a webCam connected via USB to a raspberry pi. A small python-script is reading the imageData to String an is sending it via socket to my pc. Now I want to display this imageString in a GTK image.

def updateWebCamPic(self, imageString):
    print "update"
    img = Image.open(StringIO(imageString))
    self.image.set_from_pixbuf(self.image2pixbuf(img))
    print "updatet"

def getPixBufRGB8Bit(self, im):
    arr = numpy.array(im)
    return GdkPixbuf.Pixbuf.new_from_data((arr, Gdk.COLORSPACE_RGB, 8))

def image2pixbuf(im):
    """Convert Pillow image to GdkPixbuf"""
    data = im.tobytes()
    w, h = im.size
    data = GLib.Bytes.new(data)
    pix = GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB,
            False, 8, w, h, w * 3)
    return pix

But I get the following error:

raise IOError("cannot identify image file")
IOError: cannot identify image file

[EDIT]:

if str(received[0]).startswith("<|Image|>"):
    image=received[0][9:]
    self.parrent.updateWebCamPic(image)
Starfinder
  • 11
  • 3
  • always put full error message. Which line in code generate this error ? Probably `Image.open()`. `Image.open()` expect data in format PNG, JPG, GIF, etc. – furas Jan 09 '16 at 11:47
  • see [pygame.image.tostring](https://www.pygame.org/docs/ref/image.html#pygame.image.tostring) : `string` could be use with `fromstring()` in other Python modules – furas Jan 09 '16 at 11:53
  • Its in Image.open() but how can I convert the pygame Image to png? – Starfinder Jan 09 '16 at 13:26
  • Or how can I display a surface ? – Starfinder Jan 09 '16 at 13:27
  • you probably use `PIL` or `Pillow` then check `PIL.image.fromstring()` or rather [frombytes()](http://pillow.readthedocs.org/en/3.0.x/reference/Image.html#PIL.Image.frombytes) – furas Jan 09 '16 at 13:35

0 Answers0