Results 1 to 2 of 2

Thread: setGamma/setQuality to QImage

  1. #1
    Join Date
    Mar 2009
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default setGamma/setQuality to QImage

    Hi All,

    I'm need toset/get gamma and quality/compression to/from QImage. There is very little documented about it. What I've been able to do so far is the following (e.g. for Quality):


    Qt Code:
    1. int getImageQuality(const QImage &image)
    2. {
    3. Q_ASSERT( !image.isNull() );
    4. QByteArray byteArray;
    5. QBuffer buf(&byteArray);
    6. buf.open(QIODevice::WriteOnly);
    7. QImage imageTemp(image);
    8. if (imageTemp.save(&buf, "PNG")) {
    9. QImageReader reader(&buf);
    10. return reader.quality(); // IT REACHES HERE. BUT ALWAYS RETURNS -1
    11. }
    12. return -1;
    13. }
    14.  
    15. void setQuality(int Q) // MY TEST VALUE IS 50
    16. {
    17. QBuffer buf(&ba);
    18. buf.open(QBuffer::ReadWrite);
    19. QImageWriter writer(&buf, "PNG");
    20. writer.setQuality( Q ); // SETTING A TEST VALUE 50
    21. bool ok = writer.write( myImage() );
    22. Q_ASSERT( ok );
    23. if (ok) {
    24. QImage img;
    25. ok = img.loadFromData(ba, "PNG");
    26. Q_ASSERT( ok );
    27. if (ok) {
    28. qDebug("Quality = %d", getImageQuality(img)); // ALWAYS RETURNS -1
    29. }
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

    SO, but it's not working. as if no effect.
    Can you please help me with this?

    Thanks in advance!!
    Last edited by wysota; 3rd October 2009 at 10:58.

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

    Default Re: setGamma/setQuality to QImage

    PNG is a loseless format, it doesn't support changing the quality.
    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.


Similar Threads

  1. Replies: 12
    Last Post: 7th September 2011, 17:37
  2. QImage internal error
    By GiuseppeBonfa in forum Qt Programming
    Replies: 1
    Last Post: 4th August 2009, 15:12
  3. Creating QImage of specified size from qpic
    By suneel1310 in forum Qt Programming
    Replies: 4
    Last Post: 31st March 2009, 11:53
  4. Streaming QImage (QByteArray, QDataStream, QBuffer)
    By knarz in forum Qt Programming
    Replies: 5
    Last Post: 17th January 2009, 23:05
  5. Multiple QPainters on QImage
    By fire in forum Qt Programming
    Replies: 3
    Last Post: 14th August 2008, 14:10

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.