[英]Create QImage from buffer, no deep copy?
在Qt中,如何从字节数组('uint8_t *`)构造一个QImage
对象,而不创建一个深拷贝,只是引用我的数据数组?
Use any of the constructors which take a uchar *
, for instance 例如,使用任何带有uchar *
的构造函数
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. 缓冲区必须在QImage的整个生命周期内保持有效,并且所有未复制或以其他方式从原始缓冲区中分离的副本都必须保持有效。 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. 您可以提供一个函数指针cleanupFunction以及一个额外的指针cleanupInfo,它将在销毁最后一个副本时被调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.