""" Lädt PNG-Dateien und konvertiert sie für die Anzeige in Qt und für die Vektorisierung. """ from __future__ import annotations from pathlib import Path import numpy as np from PIL import Image from PySide6.QtGui import QImage, QPixmap def load_png(path: str | Path) -> tuple[np.ndarray, int, int]: """Lädt ein PNG und gibt (RGBA-Array, Breite, Höhe) zurück.""" img = Image.open(path).convert("RGBA") pixels = np.array(img) return pixels, img.width, img.height def numpy_to_qpixmap(pixels: np.ndarray, width: int, height: int) -> QPixmap: """Konvertiert ein RGBA numpy-Array in ein QPixmap für die Qt-Anzeige.""" bytes_per_line = 4 * width qimg = QImage( pixels.data.tobytes(), width, height, bytes_per_line, QImage.Format.Format_RGBA8888, ) return QPixmap.fromImage(qimg)