【发布时间】:2015-10-13 13:20:51
【问题描述】:
我想通过套接字发送图像 Pixbuf,但接收到的图像只有黑白且失真。 以下是我正在使用的步骤:
1) 获取该 Pixbuf 的像素数组
2) 序列化像素数组
3) 将序列化的字符串转换为BytesIO
4) 通过套接字发送
MyShot = ScreenShot2()
frame = MyShot.GetScreenShot() #this function returns the Pixbuf
a = frame.get_pixels_array()
Sframe = pickle.dumps( a, 1)
b = BytesIO()
b.write(Sframe)
b.seek(0)
在此之后,我必须通过以下方式重建图像:
1) 将接收到的字符串反序列化到其原始像素数组中
2) 从像素数组构建 Pixbuf
3) 保存图片
res = gtk.gdk.pixbuf_new_from_data(pickle.loads(b.getvalue()), frame.get_colorspace(), False, frame.get_bits_per_sample(), frame.get_width(), frame.get_height(), frame.get_rowstride()) #also tried this res = gtk.gdk.pixbuf_new_from_array(pickle.loads(b.read()),gtk.gdk.COLORSPACE_RGB,8)
res.save("result.png","png")
【问题讨论】:
标签: python python-2.7 pickle gdkpixbuf bytesio