Skip to content

The only downloader you need. 下载器的集大成者。

refactor(bili_pack): 用 QImage 直接绘制二维码并升级版本

XiaoYouChR4d475492ef62
diff --git a/features/bili_pack/manifest.toml b/features/bili_pack/manifest.toml
index adb9b9c9..f8e0453e 100644
--- a/features/bili_pack/manifest.toml
+++ b/features/bili_pack/manifest.toml
@@ -2,5 +2,5 @@
entry = "pack.py"
class = "BilibiliPack"
dependencies = ["http_pack", "ffmpeg_pack"]
-version = "1.4.2"
-gdMinVersion = "4.5.0"
+version = "1.4.3"
+gdMinVersion = "4.6.0"
diff --git a/features/bili_pack/setting_cards.py b/features/bili_pack/setting_cards.py
index e8c5e7a0..be3b79fb 100644
--- a/features/bili_pack/setting_cards.py
+++ b/features/bili_pack/setting_cards.py
@@ -1,10 +1,9 @@
from __future__ import annotations
-from io import BytesIO
from typing import TYPE_CHECKING
from PySide6.QtCore import QCoreApplication, Qt, QUrl
-from PySide6.QtGui import QDesktopServices, QPixmap
+from PySide6.QtGui import QDesktopServices, QImage, QPixmap
from PySide6.QtWidgets import QHBoxLayout
from qfluentwidgets import (
@@ -27,16 +26,17 @@ if TYPE_CHECKING:
def toQrPixmap(content: str, size: int = 240) -> QPixmap:
import qrcode
- from qrcode.image.pure import PyPNGImage
- qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_M, border=2, box_size=10)
+ qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_M, border=2)
qr.add_data(content)
qr.make(fit=True)
- buf = BytesIO()
- qr.make_image(image_factory=PyPNGImage).save(buf)
- pixmap = QPixmap()
- pixmap.loadFromData(buf.getvalue(), "PNG")
- return pixmap.scaled(size, size)
+ matrix = qr.get_matrix()
+ dim = len(matrix)
+ data = bytes(0 if dark else 255 for row in matrix for dark in row)
+ image = QImage(data, dim, dim, dim, QImage.Format.Format_Grayscale8)
+ return QPixmap.fromImage(image).scaled(
+ size, size, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.FastTransformation
+ )
class ScanLoginDialog(MessageBoxBase):