gpt4 book ai didi

c++ - 从缓冲区创建 QImage,没有深拷贝?

转载 作者:太空狗 更新时间:2023-10-29 20:22:25 25 4
gpt4 key购买 nike

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

最佳答案

例如,使用任何采用uchar * 的构造函数

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

正如文档所说:

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.

关于c++ - 从缓冲区创建 QImage,没有深拷贝?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37925673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com