简体   繁体   中英

How to load an image from a buffer with Qt?

Thus type:

QBuffer* buffer = new QBuffer(this->Conex);
QImage* image = new QImage ();
image->loadFromData (buffer->buffer());

This does not work for me.

If the buffer contains raw pixel data, you might want to specify the width, height and bpp using this constructor:

QImage::QImage ( uchar * data, int width, int height, int bytesPerLine, Format format )

Edit:

That's how you would use this constructor:

int imageWidth = 800;
int imageHeight = 600;
int bytesPerPixel = 4; // 4 for RGBA, 3 for RGB
int format = QImage::Format_ARGB32; // this is the pixel format - check Qimage::Format enum type for more options
QImage image(yourData, imageWidth, imageHeight, imageWidth * bytesPerPixel, format);

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