简体   繁体   English

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

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

I want use minimum RAM when i load Image in QImage in Qt, if we don't have any information about Dpi or type(RGB16 or RGBA32 or...) of image in image header.当我在 Qt 中加载QImage中的图像时,我想使用最小 RAM,如果我们没有关于图像 header 中图像的 Dpi 或类型(RGB16 或 RGBA32 或...)的任何信息。

Any idea or code or method to detect automatically image type like ( QImage::Format_RGB32 or QImage::Format_RGB16 or...) for QImage ?有任何想法或代码或方法可以自动检测QImage的图像类型,例如( QImage::Format_RGB32QImage::Format_RGB16或...)?

The QImage is inheriting QPaintDevice . QImage继承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.想象一下它是一块 memory 的一部分,它具有一些方法和成员属性,可以解释该 memory 的内容或如何在该 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.例如,方法QImage::load将使用QImageReader实例来加载图像文件,如 JPG、PNG、BMP 等,并初始化QImage保存该数据所需的一切。 QImageReader can automatically detect image format. QImageReader可以自动检测图像格式。 You will then be able to convert this QImage instance using QImage::convertToFormat method.然后,您将能够使用QImage::convertToFormat方法转换此QImage实例。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM