68235b13 by 柴进

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

1 parent 7ad013ad
......@@ -1865,21 +1865,41 @@ class ImageGeneratorWindow(QMainWindow):
temp_file_path = temp_dir / f"clipboard_{timestamp}{file_extension}"
# 尝试多种保存方式,确保兼容性
self.logger.info(f"QImage信息: {image.width()}x{image.height()}, format={image.format()}, isNull={image.isNull()}")
success = False
# 方法1: 先转换为 RGB32 格式再保存(避免格式不兼容导致保存异常)
try:
# 方法1: 指定PNG格式
success = image.save(str(temp_file_path), "PNG")
self.logger.info(f"方法1保存结果: {success}")
except:
normalized = image.convertToFormat(QImage.Format.Format_ARGB32)
success = normalized.save(str(temp_file_path), "PNG")
self.logger.info(f"方法1(ARGB32转换)保存结果: {success}")
except Exception as e:
self.logger.warning(f"方法1保存失败: {e}")
# 方法2: 直接保存原始格式
if not success:
try:
# 方法2: 自动格式
success = image.save(str(temp_file_path))
self.logger.info(f"方法2保存结果: {success}")
except:
# 方法3: 转换格式再保存
converted_image = QImage(image)
success = converted_image.save(str(temp_file_path), "PNG")
self.logger.info(f"方法3保存结果: {success}")
success = image.save(str(temp_file_path), "PNG")
self.logger.info(f"方法2(原始格式)保存结果: {success}")
except Exception as e:
self.logger.warning(f"方法2保存失败: {e}")
# 方法3: 通过 QPixmap 中转保存
if not success:
try:
pixmap = QPixmap.fromImage(image)
success = pixmap.save(str(temp_file_path), "PNG")
self.logger.info(f"方法3(QPixmap中转)保存结果: {success}")
except Exception as e:
self.logger.warning(f"方法3保存失败: {e}")
# 验证保存的文件确实可被加载为缩略图
if success and temp_file_path.exists():
file_size = temp_file_path.stat().st_size
self.logger.info(f"保存文件大小: {file_size} bytes")
if file_size == 0:
self.logger.error("保存的文件为空(0字节)")
success = False
if success and temp_file_path.exists():
self.uploaded_images.append(str(temp_file_path))
......