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. Why am i getting this error: corrupt jpeg data: premature end of data segment
QtWS25 Last Chance

Why am i getting this error: corrupt jpeg data: premature end of data segment

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 4.4k 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.
  • M Offline
    M Offline
    Mucahit
    wrote on last edited by
    #1

    Hello everyone. I convert some data I read from the database into a picture. Some pictures look fine but in others i get this error : corrupt jpeg data, and I can take a part of the picture. I think it was caused by pixel differences. Is the problem really caused by the pixel difference ? I would be happy if you help. Thank you. My codes are below :

    QSqlQuery qry(db);

    if(qry.exec("select pim.pers_image from pers_genel pg with (nolock) left join pers_genel_image pim with (nolock) on pim.pers_num=pg.pers_no where pg.pers_no=1"))

    {
    while(qry.next())
    {
    QByteArray dataarray=qry.value(0).toByteArray();
    QPıxmap outPıxmap=QPıxmap();
    outPıxmap.loadFromData(dataarray);
    ui->label_3->setPixmap(outPixmap);
    }
    }
    else
    {
    qDebug()<<db.lastError();
    }

    Pablo J. RoginaP 1 Reply Last reply
    0
    • M Mucahit

      Hello everyone. I convert some data I read from the database into a picture. Some pictures look fine but in others i get this error : corrupt jpeg data, and I can take a part of the picture. I think it was caused by pixel differences. Is the problem really caused by the pixel difference ? I would be happy if you help. Thank you. My codes are below :

      QSqlQuery qry(db);

      if(qry.exec("select pim.pers_image from pers_genel pg with (nolock) left join pers_genel_image pim with (nolock) on pim.pers_num=pg.pers_no where pg.pers_no=1"))

      {
      while(qry.next())
      {
      QByteArray dataarray=qry.value(0).toByteArray();
      QPıxmap outPıxmap=QPıxmap();
      outPıxmap.loadFromData(dataarray);
      ui->label_3->setPixmap(outPixmap);
      }
      }
      else
      {
      qDebug()<<db.lastError();
      }

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

      @Mucahit what if you try that same query with some other external tool (i.e. query manager) and try opening the resulting file?
      Is it still corrupted?

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mucahit
        wrote on last edited by
        #3

        No, file is opening. My server machine is Windows 10 operating system. The system I am working on is running Raspbian on raspberry Pi Compute Module 3 and above. Sorry i forgot to write above maybe it might work for you.

        Pablo J. RoginaP 1 Reply Last reply
        0
        • M Mucahit

          No, file is opening. My server machine is Windows 10 operating system. The system I am working on is running Raspbian on raspberry Pi Compute Module 3 and above. Sorry i forgot to write above maybe it might work for you.

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

          @Mucahit What I tried to say was that if you could test that same query in that same device/OS and check that the ending result file is really opening fine.

          The idea was to rule out that the image was somehow stored corrupted in the DB, and then your Qt app was not the problem.

          I'd say that given you'll be working with some resource constrained device, would it be possible to add a hash column to your DB so you can retrieve that value in your query and check that what you received is actually what's stored in the DB?

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          2
          • M Offline
            M Offline
            Mucahit
            wrote on last edited by
            #5

            Frankly, I don't think there is a problem in the database part. Because when I low the pixel of the same image I want to take and reload it into the database, I show the picture very well in my qt application. so I thought it was a pixel problem but i'm not sure.

            1 Reply Last reply
            0
            • CybeXC Offline
              CybeXC Offline
              CybeX
              wrote on last edited by
              #6

              @Mucahit

              Have you seen this?

              https://wiki.qt.io/How_to_Store_and_Retrieve_Image_on_SQLite

              I would agree with @Pablo-J-Rogina. Try loading the image using an external tool (a quick google search reveals this: https://www.yohz.com/siv8_faq_view.htm) or using a simple webserver (here is some php code that should allow you to do something similar https://stackoverflow.com/questions/10850605/display-image-from-sql).

              If the image turns out badly/wrong, you know where the problem lies, if not then things would get tricky.

              1 Reply Last reply
              2
              • M Offline
                M Offline
                Mucahit
                wrote on last edited by
                #7

                Yes, I already developed my project using the resource you sent. But as I said, I can take some pictures properly but usually i can take some bad. I did test and I get the bad pictures from an external machine and pictures are very good. I think that when the pixel increases, the qbytearray variable cannot hold all the data and therefore shows only half of the image. Do you think it's the right idea? Because when I drop the pixel of the same image, I get a very smooth image.

                jsulmJ 1 Reply Last reply
                0
                • M Mucahit

                  Yes, I already developed my project using the resource you sent. But as I said, I can take some pictures properly but usually i can take some bad. I did test and I get the bad pictures from an external machine and pictures are very good. I think that when the pixel increases, the qbytearray variable cannot hold all the data and therefore shows only half of the image. Do you think it's the right idea? Because when I drop the pixel of the same image, I get a very smooth image.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Mucahit said in Why am i getting this error: corrupt jpeg data: premature end of data segment:

                  I think that when the pixel increases, the qbytearray variable cannot hold all the data and therefore shows only half of the image

                  This is very doubtful. How big are your images? How do you store them in the database? What format are these pictures?

                  "I don't think there is a problem in the database part" - you believe there is no problem, but believing is not the same as knowing. You should really do what other suggested.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1

                  • Login

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