Results 1 to 3 of 3

Thread: How to avoid correcpted images

  1. #1
    Join Date
    Feb 2016
    Posts
    15
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default How to avoid correcpted images

    Hi all ,
    I am displaying images of size 352 x 240 and in those some are corrupted images. Now , i am trying to avoid corrupted images then what i need to do .

    I have the following code
    Qt Code:
    1. if (image.pixel(image.width() - 1, image.height() - 1) == 4286611584 &&
    2. image.pixel(image.width() / 2, image.height() - 1) == 4286611584 &&
    3. image.pixel(0, image.height() - 1) == 4286611584) {
    4. val = 0; // invalid color : 4286611584 (default gray jpg)
    5. if (val == 0) {
    6.  
    7. ui->label->setPixmap(QPixmap::fromImage(image));
    8. }
    9. } else {
    10. val = 1;
    11.  
    12. if (val == 1) {
    13.  
    14. ui->label->setPixmap(QPixmap::fromImage(image));
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    In this they gave
    Qt Code:
    1. image.pixel(image.width()-1,image.height()-1 ) = 4286611584
    2. image.pixel(image.width()/2,image.height()-1 ) = 4286611584
    3. image.pixel(0,image.height()-1 ) = 4286611584
    To copy to clipboard, switch view to plain text mode 

    but i am getting different values like
    Qt Code:
    1. image.pixel(image.width()-1,image.height()-1 ) = 4278255360
    2. image.pixel(image.width()/2,image.height()-1 ) = 4278900992
    3. image.pixel(0,image.height()-1 ) = 4279949312
    To copy to clipboard, switch view to plain text mode 

    How those values are coming based on pixel or something else .

    How to calculate the image size in pixels?
    Last edited by wysota; 17th March 2016 at 07:54. Reason: missing [code] tags

  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: How to avoid correcpted images

    Quote Originally Posted by swarupa View Post
    How those values are coming based on pixel or something else .
    Based on pixel colour.

    How to calculate the image size in pixels?
    See QImage::size() or simply width()*height()
    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
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to avoid correcpted images

    JPEG images undergo lossy compression. There is no guarantee that an original pixel with colour RGB(128,128,128) will appear unmodified after being transferred to and then from JPEG format. This is especially an issue at image edges and low contrast flat areas. Open your "corrupt" image in a photo editor and closely inspect the lower right corner at high zoom.


    If the image files are actually corrupt then you cannot rely on the image size or pixel values anyway. Does isNull() return false? Does valid() return true for the pixels concerned?

Similar Threads

  1. Replies: 1
    Last Post: 17th February 2016, 15:44
  2. How to avoid this exception?
    By Gokulnathvc in forum Newbie
    Replies: 3
    Last Post: 29th August 2012, 11:26
  3. Replies: 1
    Last Post: 20th January 2011, 10:26
  4. Replies: 1
    Last Post: 16th November 2010, 17:45
  5. Replies: 4
    Last Post: 27th July 2009, 15:45

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.