处理mac打包后粘贴图片缩略图不可见的问题
Showing
1 changed file
with
32 additions
and
12 deletions
| ... | @@ -1865,21 +1865,41 @@ class ImageGeneratorWindow(QMainWindow): | ... | @@ -1865,21 +1865,41 @@ class ImageGeneratorWindow(QMainWindow): |
| 1865 | temp_file_path = temp_dir / f"clipboard_{timestamp}{file_extension}" | 1865 | temp_file_path = temp_dir / f"clipboard_{timestamp}{file_extension}" |
| 1866 | 1866 | ||
| 1867 | # 尝试多种保存方式,确保兼容性 | 1867 | # 尝试多种保存方式,确保兼容性 |
| 1868 | self.logger.info(f"QImage信息: {image.width()}x{image.height()}, format={image.format()}, isNull={image.isNull()}") | ||
| 1868 | success = False | 1869 | success = False |
| 1870 | |||
| 1871 | # 方法1: 先转换为 RGB32 格式再保存(避免格式不兼容导致保存异常) | ||
| 1869 | try: | 1872 | try: |
| 1870 | # 方法1: 指定PNG格式 | 1873 | normalized = image.convertToFormat(QImage.Format.Format_ARGB32) |
| 1871 | success = image.save(str(temp_file_path), "PNG") | 1874 | success = normalized.save(str(temp_file_path), "PNG") |
| 1872 | self.logger.info(f"方法1保存结果: {success}") | 1875 | self.logger.info(f"方法1(ARGB32转换)保存结果: {success}") |
| 1873 | except: | 1876 | except Exception as e: |
| 1877 | self.logger.warning(f"方法1保存失败: {e}") | ||
| 1878 | |||
| 1879 | # 方法2: 直接保存原始格式 | ||
| 1880 | if not success: | ||
| 1874 | try: | 1881 | try: |
| 1875 | # 方法2: 自动格式 | 1882 | success = image.save(str(temp_file_path), "PNG") |
| 1876 | success = image.save(str(temp_file_path)) | 1883 | self.logger.info(f"方法2(原始格式)保存结果: {success}") |
| 1877 | self.logger.info(f"方法2保存结果: {success}") | 1884 | except Exception as e: |
| 1878 | except: | 1885 | self.logger.warning(f"方法2保存失败: {e}") |
| 1879 | # 方法3: 转换格式再保存 | 1886 | |
| 1880 | converted_image = QImage(image) | 1887 | # 方法3: 通过 QPixmap 中转保存 |
| 1881 | success = converted_image.save(str(temp_file_path), "PNG") | 1888 | if not success: |
| 1882 | self.logger.info(f"方法3保存结果: {success}") | 1889 | try: |
| 1890 | pixmap = QPixmap.fromImage(image) | ||
| 1891 | success = pixmap.save(str(temp_file_path), "PNG") | ||
| 1892 | self.logger.info(f"方法3(QPixmap中转)保存结果: {success}") | ||
| 1893 | except Exception as e: | ||
| 1894 | self.logger.warning(f"方法3保存失败: {e}") | ||
| 1895 | |||
| 1896 | # 验证保存的文件确实可被加载为缩略图 | ||
| 1897 | if success and temp_file_path.exists(): | ||
| 1898 | file_size = temp_file_path.stat().st_size | ||
| 1899 | self.logger.info(f"保存文件大小: {file_size} bytes") | ||
| 1900 | if file_size == 0: | ||
| 1901 | self.logger.error("保存的文件为空(0字节)") | ||
| 1902 | success = False | ||
| 1883 | 1903 | ||
| 1884 | if success and temp_file_path.exists(): | 1904 | if success and temp_file_path.exists(): |
| 1885 | self.uploaded_images.append(str(temp_file_path)) | 1905 | self.uploaded_images.append(str(temp_file_path)) | ... | ... |
-
Please register or sign in to post a comment