简体   繁体   中英

Create QImage from buffer, no deep copy?

在Qt中,如何从字节数组('uint8_t *`)构造一个QImage对象,而不创建一个深拷贝,只是引用我的数据数组?

Use any of the constructors which take a uchar * , for instance

QImage::QImage(uchar *data, 
               int width, 
               int height, 
               int bytesPerLine, 
               Format format, 
               QImageCleanupFunction cleanupFunction = Q_NULLPTR, 
               void *cleanupInfo = Q_NULLPTR)

As the documentation says:

The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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