Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    4
    8
    3106
    Loading More Posts
    • 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
      Mucahit last edited by

      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. Rogina 1 Reply Last reply Reply Quote 0
      • Pablo J. Rogina
        Pablo J. Rogina @Mucahit last edited by

        @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 Reply Quote 1
        • M
          Mucahit last edited by

          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. Rogina 1 Reply Last reply Reply Quote 0
          • Pablo J. Rogina
            Pablo J. Rogina @Mucahit last edited by

            @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 Reply Quote 2
            • M
              Mucahit last edited by

              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 Reply Quote 0
              • CybeX
                CybeX last edited by

                @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 Reply Quote 2
                • M
                  Mucahit last edited by

                  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.

                  jsulm 1 Reply Last reply Reply Quote 0
                  • jsulm
                    jsulm Lifetime Qt Champion @Mucahit last edited by

                    @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 Reply Quote 1
                    • First post
                      Last post