dd2274bf by 柴进

处理mac打包后粘贴图片缩略图不可见的问题

1 parent 932fb58c
......@@ -2049,12 +2049,34 @@ class ImageGeneratorWindow(QMainWindow):
self.logger.info("开始粘贴剪贴板图片")
image = self._safe_get_clipboard_image()
if image is not None:
self.logger.info(f"成功获取剪贴板图像: {image.width()}x{image.height()}")
self.add_clipboard_image(image)
else:
if image is None:
self.logger.warning("剪贴板中没有可用的图像")
QMessageBox.information(self, "信息", "剪贴板中没有图片,请先复制一张图片")
return
self.logger.info(f"成功获取剪贴板图像: {image.width()}x{image.height()}")
# 保存到临时文件
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
temp_dir = Path(tempfile.gettempdir()) / "nano_banana_app"
temp_dir.mkdir(exist_ok=True)
temp_file_path = str(temp_dir / f"clipboard_{timestamp}.png")
normalized = image.convertToFormat(QImage.Format.Format_ARGB32)
if not normalized.save(temp_file_path, "PNG"):
if not image.save(temp_file_path, "PNG"):
self.logger.error("剪贴板图片保存失败")
QMessageBox.critical(self, "错误", "无法保存剪贴板图片")
return
self.logger.info(f"剪贴板图片已保存: {temp_file_path}")
# 走和"添加图片"按钮完全相同的路径
self.uploaded_images.append(temp_file_path)
self.update_image_preview()
self.image_count_label.setText(f"已选择 {len(self.uploaded_images)} 张")
self.status_label.setText("● 已添加剪贴板图片")
self.status_label.setStyleSheet("QLabel { color: #34C759; }")
except Exception as e:
self.logger.error(f"粘贴剪贴板图片时发生错误: {str(e)}", exc_info=True)
......