Skip to content

Commit 9db3a1b

Browse files
committed
fix(qr): 修复二维码生成和保存功能
- 添加了 PyPNGImage 导入以支持 PNG 格式生成 - 修改二维码生成逻辑使用 image_factory 参数 - 简化图片保存流程移除手动格式指定 - 添加异常重新抛出确保错误处理正确性
1 parent 283fcdd commit 9db3a1b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

features/bili_pack/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
PrimaryPushButton,
2929
PixmapLabel,
3030
)
31+
from qrcode.image.pure import PyPNGImage
3132

3233
from app.bases.models import PackConfig
3334
from app.services.core_service import coreService
@@ -104,9 +105,9 @@ def _createQrPixmap(content: str, size: int = 240) -> QPixmap:
104105
qrCode.add_data(content)
105106
qrCode.make(fit=True)
106107

107-
image = qrCode.make_image(fill_color="black", back_color="white").convert("RGB")
108+
image = qrCode.make_image(image_factory=PyPNGImage, fill_color="black", back_color="white")
108109
buffer = BytesIO()
109-
image.save(buffer, format="PNG")
110+
image.save(buffer)
110111

111112
pixmap = QPixmap()
112113
pixmap.loadFromData(buffer.getvalue(), "PNG")
@@ -529,6 +530,7 @@ def _onQrCodeGenerated(self, generation: int, result: dict | None, error: str |
529530
self.qrPixmapLabel.setPixmap(_createQrPixmap(self._loginUrl))
530531
except Exception as e:
531532
self.statusLabel.setText(self.tr(f"二维码生成失败:{e}"))
533+
raise e
532534
return
533535

534536
self.openBrowserButton.setEnabled(True)

0 commit comments

Comments
 (0)