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")
好主意,謝謝:) –