I'm trying to display image that I receive from a test local server inside pyqt window. I tried this link but I couldn't get it work. Could you help with that? Thanks in advance.
Displaying Image (in bytes) in PyQt
Client Code
import socket
from PIL import Image
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtGui import QIcon, QPixmap
app = QApplication(sys.argv)
widget = QWidget()
label = QLabel(widget)
HOST = socket.gethostbyname(socket.gethostname())
PORT = 5000
s = socket.socket()
s.connect((HOST, PORT))
while True:
image_binaries = s.recv(100000000)
if not image_binaries:
break
#img = Image.open(BytesIO(image_binaries))
pixmap = QPixmap()
pixmap.loadFromData(image_binaries)
label.setPixmap(pixmap)
widget.resize(pixmap.width(), pixmap.height())
widget.show()
sys.exit(app.exec_())
Server Code
import socket
HOST = "0.0.0.0"
PORT = 5000
s = socket.socket()
s.bind((HOST, PORT))
data = open(r'Screenshot_1.jpg', 'rb').read()
print("Waiting for connection...")
s.listen(5)
while True:
client, client_address = s.accept()
print(client_address, "is connected")
client.send(data)