user950489
user950489

Reputation: 21

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.

Upvotes: 2

Views: 8113

Answers (1)

laurent
laurent

Reputation: 90746

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);

Upvotes: 5

Related Questions