dd2274bf by 柴进

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

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