I'm new to C++ and Qt but I was wondering if anyone could help me.
I have a raw image file named fb0
with the following properties:
Width: 1024
Height: 768
Format: rgb565 (QImage::Format_RGB16?)
How would I go about loading the data from fb0
and then displaying this image in a Qt GUI?
Solution:
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();
You need to do something like:
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.
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.