in Qt, how can I construct a QImage
object from a byte array ('uint8_t*`), without creating a deep copy, just referring to my data array?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With