0
我想通过套接字发送图像Pixbuf,但接收到的图像只有黑白和扭曲。 下面是我使用以下步骤:从GDK Pixbuf重新构建PNG图像
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)从像素阵列
3构建的pixbuf)保存图像
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")
好主意,谢谢:) –