我正在尝试将png图像(屏幕快照)从服务器发送到客户端.
我对其进行解码,然后将解码后的字符串发送给客户端,客户端使用它将图像保存在他的计算机中.
但是我从客户那里得到的图像并不完美,…
客户
while "finish" not in data:
data += receive(data_len)
data = data[:-7]
fh = open("imageToSave.png", "wb")
fh.write(data.decode('base64'))
fh.close()
服务器
ImageGrab.grab().save("screen_capture.png", "PNG")
#Convert the image to a string that it will be able to be send to the client
with open("screen_capture.png", "rb") as imageFile:
Image_Str = base64.b64encode(imageFile.read())
fh = open("text", "wb")
fh.write(Image_Str)
fh.close
fh = open("text", "rb")
str1 = fh.read(150)
client_socket.send("150~" + str1)
while str1:
str1 = fh.read(150)
client_socket.send(str1)
client_socket.send("6finish")
我试图检查字符串是否相同-好像它们是..
当我尝试将字符串解码回服务器中的图像时,它可以工作…