如何在Qt GUI中显示原始图像文件? [英] How to display a raw image file in a Qt GUI?
本文介绍了如何在Qt GUI中显示原始图像文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是C ++和Qt的新手,但我想知道是否有人可以帮助我。
I'm new to C++ and Qt but I was wondering if anyone could help me.
我有一个名为 fb0的原始图片文件
具有以下属性:
I have a raw image file named fb0
with the following properties:
Width: 1024
Height: 768
Format: rgb565 (QImage::Format_RGB16?)
我如何从<$然后在Qt GUI中显示此图片?
How would I go about loading the data from fb0
and then displaying this image in a Qt GUI?
解决方案:
QFile file("C:\\Users\\Username\\Desktop\\RawImage.raw");
if (!file.open(QFile::ReadOnly))
{
qDebug("Could not open file");
} else {
qDebug() << file.fileName() << " opened";
}
QByteArray array =file.readAll();
unsigned char* Data = (unsigned char*)&array.data()[0];
QImage myImage(Data,1024,768,QImage::Format_RGB16);
QLabel myLabel;
myLabel.setPixmap(QPixmap::fromImage(myImage));
myLabel.show();
推荐答案
您需要执行以下操作:
QFile file("yourFile.raw");
if (!file.open(QFile::ReadOnly)) return;
QByteArray array = file.readAll();
QImage image(array.data(), w, h, QImage::Format_RGB16);
尚未测试过。脑到终端。
Haven't tested it though. Brain to terminal.
这篇关于如何在Qt GUI中显示原始图像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文