52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
|
|
#### Same thread as main.py so it will be relatively unresponsive. Just for use locally for a faster image display from buffer.
|
|
|
|
|
|
from PySide6.QtWidgets import QApplication, QLabel
|
|
from PySide6.QtCore import Qt
|
|
from PySide6.QtGui import QImage, QPixmap
|
|
import sys
|
|
def create_viewer():
|
|
"""Create and return a QLabel widget for displaying images"""
|
|
app = QApplication.instance()
|
|
if app is None:
|
|
app = QApplication(sys.argv)
|
|
|
|
label = QLabel()
|
|
label.setWindowTitle("Image Viewer")
|
|
label.setMinimumSize(640, 480)
|
|
# Enable mouse tracking for potential future interactivity
|
|
label.setMouseTracking(True)
|
|
# Better scaling quality
|
|
label.setScaledContents(True)
|
|
label.show()
|
|
|
|
return label, app
|
|
|
|
def show_buffer_image(buffer, label):
|
|
"""
|
|
Display an image from buffer using PySide6
|
|
|
|
Parameters:
|
|
buffer: bytes
|
|
Raw image data in memory
|
|
label: QLabel
|
|
Qt label widget to display the image
|
|
"""
|
|
# Convert buffer to QImage
|
|
qimg = QImage.fromData(buffer)
|
|
|
|
# Convert to QPixmap and set to label
|
|
pixmap = QPixmap.fromImage(qimg)
|
|
|
|
# Scale with better quality
|
|
scaled_pixmap = pixmap.scaled(
|
|
label.size(),
|
|
Qt.KeepAspectRatio,
|
|
Qt.SmoothTransformation
|
|
)
|
|
|
|
label.setPixmap(scaled_pixmap)
|
|
|
|
# Process Qt events to update the display
|
|
QApplication.processEvents() |