来自unsigned char缓冲区的QImage(jpg格式) [英] QImage from unsigned char buffer (jpg format)

查看:1480
本文介绍了来自unsigned char缓冲区的QImage(jpg格式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 unsigned char * 类型的缓冲区,我用JPG图像填充。我想使用这个缓冲区在QLabel中将图像绘制到我的应用程序屏幕。

I have buffer of type unsigned char* which I fill with JPG image. I want to use this buffer to draw the image to my application screen in a QLabel.

我已经完成了这个,但是图像不正确。

I've done this, but the image is incorrect.

谁能告诉我最好的方法是什么?

Can anyone tell me what the best way to do this is?

QPixmap pix = QPixmap::fromImage(
     QImage(buff, 460, 345, QImage::Format_RGB888)); //Not sure what format to use for a jpg image?

one_img->setPixmap(pix);  //one_img is of type QLabel.


推荐答案

QImage :: load QImage 构造函数期望图像缓冲区处于未压缩格式。

QImage::load or the QImage constructor expect the image buffer to be in an uncompressed format.

如果你不打算修改图像,使用 QPixmap 及其 loadFromData()函数:

If you don't intend to modify the image, use QPixmap and its loadFromData() function:

QPixmap pix;
pix.loadFromData(buff, sizeOfBuff, "JPG");

您还可以使用 QImage :: fromData / QImage :: loadFromData ,或 QImageReader + QBuffer

You can also load a Jpeg buffer with QImage::fromData / QImage::loadFromData, or QImageReader + QBuffer.

这篇关于来自unsigned char缓冲区的QImage(jpg格式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆