QImage::Format_Mono
, QImage::Format_RGB32
, QImage::Format_ARGB32
, QImage::Format_ARGB32_Premultiplied
, 和 QImage::Format_RGB555
是 Qt 中不同的图像像素格式,它们在存储方式、颜色深度、是否支持透明通道以及适用场景上各有不同。下面是它们的详细对比:
Format_Mono
Format_RGB555
RGB32
更节省内存Format_RGB32
Format_ARGB32
Format_ARGB32_Premultiplied
格式 | 内存/像素 | 是否透明 | 是否调色板 | 主要用途 | 特点 |
---|---|---|---|---|---|
Format_Mono |
1 bit | ❌ | ❌ | 黑白图像、文档打印 | 极低内存,仅黑白 |
Format_RGB555 |
16 bit | ❌ | ❌ | 低资源设备彩色图像 | 色彩有限,内存少 |
Format_RGB32 |
32 bit | ❌ | ❌ | 全彩图像显示 | 色彩丰富,无透明 |
Format_ARGB32 |
32 bit | ✅ | ❌ | 支持透明度的图像处理 | 原始 Alpha 数据 |
Format_ARGB32_Premultiplied |
32 bit | ✅ | ❌ | GPU 渲染、快速合成 | Alpha 预乘,渲染高效 |
场景 | 推荐格式 |
---|---|
简单黑白图像(如图标、遮罩) | Format_Mono |
彩色图像处理(含 UI 设计、绘图工具) | Format_RGB32 |
支持透明度的图像处理(如 PNG) | Format_ARGB32 |
GPU 渲染、视频输出、快速合成 | Format_ARGB32_Premultiplied |
旧设备兼容性需求 | Format_RGB555 |
QImage image("input.png");
QImage rgbaImage = image.convertToFormat(QImage::Format_ARGB32); // 支持透明度
QImage rgb32Image = image.convertToFormat(QImage::Format_RGB32); // 去掉透明度
QImage monoImage = image.convertToFormat(QImage::Format_Mono); // 转换为黑白
如你的代码中有 image.fill(Qt::transparent)
,说明你希望支持透明背景,推荐使用 Format_ARGB32
或 Format_ARGB32_Premultiplied
。