I have successfully sent an image through a socket and, on the receiving end, I have the exact same raw bytes that the image file that was sent had. This means that if I binary write those bytes to a file, I'll obtain the same file as the one that was sent. I have tried showing the image from Python without saving it first, but I'm having trouble doing so. If I understand correctly, matplotlib.imread()
requires the path to a file and then decodes that file into several matrices. Doing something like this works fine:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
# data is the image data that was received from the socket
file = open("d:\\image.png", 'wb')
file.write(data)
file.close()
img = mpimg.imread("d:\\image.png")
plt.imshow(img)
plt.show()
Obviously I should use a temporary file for that, but I wrote that just for the sake of the example. Is there any way to call the imshow()
and show()
methods without having called imread()
beforehand, provided I already have those bytes?