Results 1 to 19 of 19

Thread: Saving QPixmap resutls in corrupt JPG

  1. #1
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Saving QPixmap resutls in corrupt JPG

    Hi! When I try to save a QPixmap in Windows, it results in a corrupt JPG file, black or black with white lines. But it doesn't happen in all computers, I tried in four and in two happens, in the other two not.

    Saving in PNG doesn't have any errors.

    Any ideas???

    Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Saving QPixmap resutls in corrupt JPG

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving QPixmap resutls in corrupt JPG

    Hi! Thanks for your reply. Here is the example that fails. Basically it loads a photo into a label and then saves it:

    Qt Code:
    1. void MainWindow::on_savePushButton_clicked()
    2. {
    3. [...]
    4.  
    5. if (!photoLabel->pixmap()->save(QString("fotos/%1.jpg").arg(regLineEdit->displayText()), 0, 100))
    6. QMessageBox::warning(this, qApp->applicationName(), "Error");
    7.  
    8. [...]
    9. }
    10.  
    11. void MainWindow::loadPhoto()
    12. {
    13. QPixmap pixmap;
    14.  
    15. QString path = QString("fotos/%1.jpg").arg(cardsModel->index(mapper->currentIndex(), ViewCardsTableModel::Registration).data().toString());
    16.  
    17. if (!pixmap.load(path))
    18. {
    19. QMessageBox::critical(this, qApp->applicationName(), QString("Error.").arg(cardsModel->index(mapper->currentIndex(), ViewCardsTableModel::Registration).data().toString()));
    20. photoLabel->setPixmap(QPixmap());
    21. }
    22. else
    23. photoLabel->setPixmap(pixmap);
    24. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Saving QPixmap resutls in corrupt JPG

    This is neither minimal nor compilable.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving QPixmap resutls in corrupt JPG

    Sorry, it's too much code. But it's simple, just this:

    Qt Code:
    1. QPixmap pixmap;
    2. pixmap.load("photo.jpg");
    3. pixmap.save("photo2.jpg");
    To copy to clipboard, switch view to plain text mode 

    Don't work. I get the attached image.


  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Saving QPixmap resutls in corrupt JPG

    Does it happen for every jpeg image or this particular one?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving QPixmap resutls in corrupt JPG

    For every JPEG, but if I use QImage instead QPixmap it works, so it's not because jpeg plugin (I think).

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Saving QPixmap resutls in corrupt JPG

    Well... saving the picture is done by the same code (QImageWriter) regardless if you use QPixmap or QImage as one is converted to the other so if it matters whether you use QPixmap or QImage, I'd say Qt is not to be blamed.

    So the following doesn't work?
    Qt Code:
    1. #include <QtGui>
    2. int main(int argc, char **argv){
    3. QApplication app(argc, argv);
    4. QPixmap px;
    5. px.load("input.jpeg");
    6. px.save("output.jpeg");
    7. return 0;
    8. }
    To copy to clipboard, switch view to plain text mode 

    And the following does?
    Qt Code:
    1. #include <QtGui>
    2. int main(int argc, char **argv){
    3. QApplication app(argc, argv);
    4. QImage px;
    5. px.load("input.jpeg");
    6. px.save("output.jpeg");
    7. return 0;
    8. }
    To copy to clipboard, switch view to plain text mode 

    Please check both snippets.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving QPixmap resutls in corrupt JPG

    That's right, I checked it and the first doesn't work, the second does.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Saving QPixmap resutls in corrupt JPG

    Quote Originally Posted by Pit View Post
    That's right, I checked it and the first doesn't work, the second does.
    This exact same code, right? What platform are you using and which version of Qt (you might want to update your QtCentre profile to avoid such questions in future)?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving QPixmap resutls in corrupt JPG

    Yes, this exact same code. I'm using Windows XP SP3 and Qt 4.6.3 (thanks for the advice ). This code works in another computer with XP SP3, but it doesn't in the computer with QT installed, neither in another with XP SP3 too.

  12. #12
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving QPixmap resutls in corrupt JPG

    I tried this, but it failed too:

    Qt Code:
    1. #include <QtGui>
    2. int main(int argc, char **argv){
    3. QApplication app(argc, argv);
    4. QImage img;
    5. img.load("input.jpeg");
    6. px = QPixmap::fromImage(img);
    7. px.save("output.jpeg");
    8. return 0;
    9. }
    To copy to clipboard, switch view to plain text mode 

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Saving QPixmap resutls in corrupt JPG

    One more try:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv){
    4. QApplication app(argc, argv);
    5. QImage img = QImageReader("input.jpeg").read(); // this is almost exactly
    6. QPixmap px = QPixmap::fromImage(img); // what QPixmap::load() does
    7. QLabel l;
    8. l.setPixmap(px);
    9. l.show();
    10. px.save("output.jpeg");
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    Is the label correct? Is output.jpeg corrupted?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving QPixmap resutls in corrupt JPG

    The label is correct, and output.jpeg is corrupted. That happens in my program too, I have a label and I put the QPixmap there, but when I save it the jpeg is corrupted. The problem appears to be the save function

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Saving QPixmap resutls in corrupt JPG

    Save essentially does this:
    Qt Code:
    1. QPixmap px(...);
    2. QImage img = px.toImage();
    3. QImageWriter writer(fiileName);
    4. writer.write(img);
    To copy to clipboard, switch view to plain text mode 

    Try this piece of code:
    Qt Code:
    1. int main(...) {
    2. QApplication app(argc, argv);
    3. QLabel l;
    4. QImage img("input.jpeg");
    5. QPixmap px = QPixmap::fromImage(img);
    6. img = px.toImage();
    7. px = QPixmap::fromImage(img);
    8. l.setPixmap(px);
    9. l.show();
    10. img.save("output_image.jpeg", "JPEG");
    11. px.save("output_pixmap.jpeg", "JPEG");
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    Basically Qt loads and saves pixmaps and images using the same code, so essentially either both or none of them should work so if what you experience is different, there might be something wrong with your installation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving QPixmap resutls in corrupt JPG

    Same result. Label shows correctly, but both output_image and output_pixmap are corrupted. I will go to install QT in the computer that works, and compile from them and see the result. I'll post the results soon. Thank you

  17. #17
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving QPixmap resutls in corrupt JPG

    Hmmmm... I installed QT 4.6.3 in the computer where the program works. After install, QPixmap fails again

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Saving QPixmap resutls in corrupt JPG

    I think there is some software installed on your computer which causes malfunction of libjpeg or something like that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #19
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving QPixmap resutls in corrupt JPG

    Well... I don't know what is wrong. I tried in many computers, some of them works, some don't, so finally I'm saving in PNG format... Thanks for all anyway

Similar Threads

  1. QTCPsocket data corrupt when receive
    By gabizzz in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2010, 17:29
  2. I Think that qsqlpsqld4 is corrupt
    By Aureon in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2010, 10:37
  3. Saving the widget class as a QPixmap
    By zgulser in forum Newbie
    Replies: 11
    Last Post: 2nd February 2009, 09:48
  4. Saving a QPixmap Object problem
    By StrikerX in forum General Programming
    Replies: 4
    Last Post: 15th November 2007, 02:19
  5. Corrupt JPEG data
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 13th January 2007, 16:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.