Results 1 to 19 of 19

Thread: Saving QPixmap resutls in corrupt JPG

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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,360
    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,360
    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,360
    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,360
    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,360
    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.

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.