来自无符号字符缓冲区的 QImage(jpg 格式)
我有 unsigned char*
类型的缓冲区,我用 JPG 图像填充它。我想使用此缓冲区将图像绘制到 QLabel 中的应用程序屏幕上。
我已经这样做了,但图像不正确。
谁能告诉我最好的方法是什么?
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
QImage::load
或QImage
构造函数期望图像缓冲区采用未压缩格式。如果您不打算修改图像,请使用
QPixmap
及其loadFromData()
函数:您还可以使用
QImage::fromData<加载Jpeg缓冲区/code> /
QImage::loadFromData
或QImageReader
+QBuffer
。QImage::load
or theQImage
constructor expect the image buffer to be in an uncompressed format.If you don't intend to modify the image, use
QPixmap
and itsloadFromData()
function:You can also load a Jpeg buffer with
QImage::fromData
/QImage::loadFromData
, orQImageReader
+QBuffer
.这可能与图像格式有关。这取决于将图像加载到缓冲区的方式。
QImage
期望在提供的缓冲区中找到逐行存储的图像。尝试使用
Format_Indexed8
或Format_RGB32
图像格式。如果仍然不起作用,请告诉我们您如何将jpeg
图像加载到缓冲区中。请注意,
QImage
提供了一个构造函数以图像文件名作为参数。Probably this has to do with the image format. It depends on the way you load the image into the buffer.
QImage
expects to find an image stored line by line in the provided buffer.Try the
Format_Indexed8
orFormat_RGB32
image formats. If it still does not work let us know how you have loaded thejpeg
image into the buffer.Notice that
QImage
provides a constructor with the image filename as argument.正确的方法是不要将 jpg 数据解释为 RGB 格式,并使用适当的类,例如 QImageReader,或事件使用构造函数直接加载图像。
The correct way is not to interpret the jpg data as RGB format, and use appropriate class, like for example QImageReader, or event use the constructor to load the image directly.
你说你用 jpg 填充缓冲区,所以看起来你已经保存了一个图像。
如果是这样,最好的方法是使用:
QPixmap ( const QString & 文件名, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor )
其中:
you said that you fill the buffer with an jpg, so it seem that you have an image already saved.
if so the best way is to use:
QPixmap ( const QString & fileName, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor )
where :