Only read part of a binary file
-
wrote on 17 Oct 2015, 21:59 last edited by
I'm a Qt beginner and would like a little direction to help me get started.
I want to draw an embedded jpeg from a raw camera file in an imageLabel. I have done this successfully by editing a raw file in a hex editor, eliminating all of the file except the embedded jpeg and then tested using this code:
QFile file("D:/Rory/Pictures/test2.nef"); file.open(QIODevice::ReadOnly); QByteArray buf = file.readAll(); QImage *image = new QImage; image->loadFromData(buf); imageLabel->setPixmap(QPixmap::fromImage(*image)); ...
I want to populate buf with only the embedded jpeg from the NEF raw image file. I need to find the file offset for the first instance of hex FFD8 and then read until hex FFD9. I think I should iterate through the file using qFile::seek to find the offsets for FFD8 and FFD9, use qFile::pos to move to FFD8 and qFile::read(the offset difference between FFD8 and FFD9).
Am I on the right path? And if so, is there any sample code to help me?
Many thanks in advance.
-
I'm a Qt beginner and would like a little direction to help me get started.
I want to draw an embedded jpeg from a raw camera file in an imageLabel. I have done this successfully by editing a raw file in a hex editor, eliminating all of the file except the embedded jpeg and then tested using this code:
QFile file("D:/Rory/Pictures/test2.nef"); file.open(QIODevice::ReadOnly); QByteArray buf = file.readAll(); QImage *image = new QImage; image->loadFromData(buf); imageLabel->setPixmap(QPixmap::fromImage(*image)); ...
I want to populate buf with only the embedded jpeg from the NEF raw image file. I need to find the file offset for the first instance of hex FFD8 and then read until hex FFD9. I think I should iterate through the file using qFile::seek to find the offsets for FFD8 and FFD9, use qFile::pos to move to FFD8 and qFile::read(the offset difference between FFD8 and FFD9).
Am I on the right path? And if so, is there any sample code to help me?
Many thanks in advance.
wrote on 17 Oct 2015, 22:13 last edited by -
wrote on 17 Oct 2015, 23:08 last edited by
Thanks, QDataStream looks promising.
1/3