Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Only read part of a binary file
Forum Update on Monday, May 27th 2025

Only read part of a binary file

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rory_1
    wrote on 17 Oct 2015, 21:59 last edited by
    #1

    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.

    T 1 Reply Last reply 17 Oct 2015, 22:13
    0
    • R Rory_1
      17 Oct 2015, 21:59

      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.

      T Offline
      T Offline
      t3685
      wrote on 17 Oct 2015, 22:13 last edited by
      #2

      @Rory_1

      You can also consider using QDataStream:

      http://doc.qt.io/qt-5/qdatastream.html

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rory_1
        wrote on 17 Oct 2015, 23:08 last edited by
        #3

        Thanks, QDataStream looks promising.

        1 Reply Last reply
        0

        1/3

        17 Oct 2015, 21:59

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved