Only read part of a binary file

  • 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");;
    QByteArray buf = file.readAll();
    QImage *image = new QImage;

    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.

  • @Rory_1

    You can also consider using QDataStream:

  • Thanks, QDataStream looks promising.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.