如何检测 QImage 消耗最少 RAM 的足够格式(数据类型)?

How to detect sufficient format(data type) for QImage to consume minimum RAM?

如果我们没有任何关于图像中图像的 Dpi 或类型(RGB16 或 RGBA32 或...)的信息,我想在 Qt 中加载 QImage 中的图像时使用最小 RAM header.

自动检测图像类型(QImage::Format_RGB32QImage::Format_RGB16 的任何想法或代码或方法 或...) QImage?

QImage is inheriting QPaintDevice. It's not a binary format of an image nor contains or anything else like that. Imagine it as a piece of memory with some methods and member properties that can explain the content of that memory or how you can draw pixels on that piece of memory. For example, the method QImage::load will use the QImageReader instance to load an image file like JPG, PNG, BMP, etc and initializes everything needed for QImage to hold that data. QImageReader可以自动检测图片格式。 然后您将能够转换此 QImage instance using QImage::convertToFormat 方法。

QImage img;
img.load("/some/path/to/sample.png");
QImage converted = img.convertToFormat(QImage::Format_RGB16);