Results 1 to 19 of 19

Thread: Why show the incorrect TIFF image by QImageReader Read

  1. #1
    Join Date
    Dec 2012
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60 Android Maemo/MeeGo

    Default Why show the incorrect TIFF image by QImageReader Read

    Hi, all
    I am developping a project about picture analise. And i load a tiff image then show,the image only display a half pixel,and another half pixel lost.In addition, when i scale the image window, only when scaled to 50%,the image clear display,if other scale, image display with vertical white bar.

    tips: only less of TIFF images happened.

    1. Please give me some advice on how to solve this problem or How to improve. If each byte did not alignment?

    Qt Code:
    1. QImageReader imageReader( mstrImagePath );
    2. QImage pic = imageReader.read();
    3. painter->drawImage( QRectF(0, 0, pic.width(), pic.height()), pic );
    To copy to clipboard, switch view to plain text mode 

  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: Why show the incorrect TIFF image by QImageReader Read

    Does QImage::width() and QImage::height() return proper values for your "bad" images?
    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
    Dec 2012
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60 Android Maemo/MeeGo

    Default Re: Why show the incorrect TIFF image by QImageReader Read

    Thanks to wysota about my question.

    And i have comforned that the width and height is correct. And i attach a screenshot about a original image and two different scaled images.

    Hope you can give me some advice and let me go ahead.

    originalImage.jpgscreenshot50%.jpgscreenshot75%.jpg
    Last edited by johenny; 8th April 2013 at 02:54.

  4. #4
    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: Why show the incorrect TIFF image by QImageReader Read

    How are you resizing the image? What are you painting on to? Where is the painting code?
    Last edited by ChrisW67; 8th April 2013 at 04:06.

  5. #5
    Join Date
    Dec 2012
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60 Android Maemo/MeeGo

    Default Re: Why show the incorrect TIFF image by QImageReader Read

    Quote Originally Posted by ChrisW67 View Post
    How are you resizing the image? What are you paining on to? Where is the painting code?
    1. I never resize the image. -- the original image is TIFF format.
    2. paint on to QGraphicsView.
    3. paint code : painter->drawImage( QRectF(0, 0, pic.width(), pic.height()), pic );

    I dont understand your question means? What is the key you want me to care?

  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: Why show the incorrect TIFF image by QImageReader Read

    Quote Originally Posted by johenny View Post
    3. paint code : painter->drawImage( QRectF(0, 0, pic.width(), pic.height()), pic );
    Where do you call that code? What does the painter operate on?
    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
    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: Why show the incorrect TIFF image by QImageReader Read

    So you are calling drawImage() in the paintEvent() of a subclassed QGraphicsView to get some sort of background? Or is your painting code outside the paintEvent() where it is unlikely to be reliable?

    Do you really just want to put your image into a QGraphicsPixmapItem that you insert into the scene?

  8. #8
    Join Date
    Dec 2012
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60 Android Maemo/MeeGo

    Default Re: Why show the incorrect TIFF image by QImageReader Read

    As ChrisW67 says, i am calling drawImage() in the QGraphicsView::drawBackground( QPainter*,QRectF&).

    And my confusion is whether these tiff image have muti-layer and how to improve by qt? Because only some special TIFF image have this problem, and these image preview tell me that the half image pixel(or color) lost. So i dont konw how to improve by QT.

    And now i try to add some 3th library to test these image.

    If you have any suggest, welcome to tell me ,thanks!

  9. #9
    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: Why show the incorrect TIFF image by QImageReader Read

    Quote Originally Posted by johenny View Post
    As ChrisW67 says, i am calling drawImage() in the QGraphicsView::drawBackground( QPainter*,QRectF&).
    And how do you ensure the image actually fits in the view?
    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.


  10. #10
    Join Date
    Dec 2012
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60 Android Maemo/MeeGo

    Default Re: Why show the incorrect TIFF image by QImageReader Read

    Quote Originally Posted by wysota View Post
    And how do you ensure the image actually fits in the view?
    Just i can load a original size image into the view, so i feel to. Or you can teach me a way to ensure?

  11. #11
    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: Why show the incorrect TIFF image by QImageReader Read

    If you are painting in drawBackground() then painting is done in scene coordinates and rect is the exposed rectangle. That coordinate system is not pixels tied to the top-left of the viewport. Try this program with a simple 512x512 pixel TIFF to see the difference as you resize the window.

    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. class View: public QGraphicsView
    5. {
    6. Q_OBJECT
    7. public:
    8. View(QGraphicsScene *scene, QWidget *p = 0): QGraphicsView(scene, p)
    9. {
    10. }
    11. protected:
    12. void drawBackground(QPainter *painter, const QRectF &rect)
    13. {
    14. static const QImage pic("test.tif");
    15. qDebug() << pic.size() << rect << viewport()->size();
    16. painter->drawImage(QRectF(0.0, 0.0, pic.width(), pic.height()), pic);
    17. }
    18. };
    19.  
    20. int main(int argc, char **argv)
    21. {
    22. QApplication app(argc, argv);
    23. scene.addText("Hello, world!");
    24.  
    25. View v(&scene);
    26. v.show();
    27. return app.exec();
    28. }
    29. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  12. #12
    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: Why show the incorrect TIFF image by QImageReader Read

    Quote Originally Posted by johenny View Post
    Just i can load a original size image into the view,
    You're not loading anything into the view. The view has no notion about your image, it will not resize to it or anything like that. If you want to "load image into the view" then use QGraphicsScene::addPixmap() or instantiate QGraphicsPixmapItem manually and add it to the scene.
    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.


  13. #13
    Join Date
    Dec 2012
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60 Android Maemo/MeeGo

    Default Re: Why show the incorrect TIFF image by QImageReader Read

    Quote Originally Posted by wysota View Post
    You're not loading anything into the view. The view has no notion about your image, it will not resize to it or anything like that. If you want to "load image into the view" then use QGraphicsScene::addPixmap() or instantiate QGraphicsPixmapItem manually and add it to the scene.
    I am sure i have loaded it into the view,because of the code is too much, so i just paste a litter.

    And i hope you can give me a e-mail,and i can send 2 image to you. You can use Qt Demo(QWidget-Image Viewer) to show the effect. OK?

    Quote Originally Posted by ChrisW67 View Post
    If you are painting in drawBackground() then painting is done in scene coordinates and rect is the exposed rectangle. That coordinate system is not pixels tied to the top-left of the viewport. Try this program with a simple 512x512 pixel TIFF to see the difference as you resize the window.

    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. class View: public QGraphicsView
    5. {
    6. Q_OBJECT
    7. public:
    8. View(QGraphicsScene *scene, QWidget *p = 0): QGraphicsView(scene, p)
    9. {
    10. }
    11. protected:
    12. void drawBackground(QPainter *painter, const QRectF &rect)
    13. {
    14. static const QImage pic("test.tif");
    15. qDebug() << pic.size() << rect << viewport()->size();
    16. painter->drawImage(QRectF(0.0, 0.0, pic.width(), pic.height()), pic);
    17. }
    18. };
    19.  
    20. int main(int argc, char **argv)
    21. {
    22. QApplication app(argc, argv);
    23. scene.addText("Hello, world!");
    24.  
    25. View v(&scene);
    26. v.show();
    27. return app.exec();
    28. }
    29. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    Thanks,i try it.
    And i hope you can give me a e-mail,and i can send 2 image to you. You can use Qt Demo(QWidget-Image Viewer) to show the effect. OK?

    Thanks again to wysota and ChrisW67.

  14. #14
    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: Why show the incorrect TIFF image by QImageReader Read

    Quote Originally Posted by johenny View Post
    I am sure i have loaded it into the view,because of the code is too much, so i just paste a litter.
    Please show us how you loaded the image into the view and tell us what do you need the drawBackground implementation for then.
    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.


  15. #15
    Join Date
    Dec 2012
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60 Android Maemo/MeeGo

    Default Re: Why show the incorrect TIFF image by QImageReader Read

    Quote Originally Posted by wysota View Post
    Please show us how you loaded the image into the view and tell us what do you need the drawBackground implementation for then.
    My question is how to display the right image by QT. Whether i need to improve the image data? The qt demo can not show it correct. my email is jjin@ubmtechinsights.com.if ok, you can send email to me, and i hope to send the special image to you, after that,you can give me some advice.

  16. #16
    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: Why show the incorrect TIFF image by QImageReader Read

    I will not send you my email. If you want help then please state how you load the image into the view and why you reimplement drawBackground().
    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.


  17. #17
    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: Why show the incorrect TIFF image by QImageReader Read

    You can post a sample TIFF file as an attachment to a post here if it's not too big. You will need to zip it first to meet the allowed types.

    TIFF files cover a huge range of variations. I would be surprised all of them are supported by the Qt TIFF plugin. I cannot, for example, see a way to handle layers/multiple images from Qt (a baseline TIFF reader is not required to) although the underlying library can.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  18. #18
    Join Date
    Dec 2012
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60 Android Maemo/MeeGo

    Default Re: Why show the incorrect TIFF image by QImageReader Read

    Quote Originally Posted by ChrisW67 View Post
    You can post a sample TIFF file as an attachment to a post here if it's not too big. You will need to zip it first to meet the allowed types.
    Thanks, but this TIFF file is too big.

    And i think this tiff image has multiple layer images. Because if i use photoshop to edit a image, then add a layer into the image, not merge but save it, this saved image is not been displayed normally by QT.

    So, i am trying to add a library(libtiff), but i want to know what Qt TIFF plugin can do(what can i try to do)? or other solution ?
    Last edited by johenny; 9th April 2013 at 02:50.

  19. #19
    Join Date
    Dec 2012
    Posts
    9
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60 Android Maemo/MeeGo

    Default Re: Why show the incorrect TIFF image by QImageReader Read

    Add CxImage library to slove this problem. The reason maybe the image had not been flatted.
    Thanks to ChrisW67 and wysota.

Similar Threads

  1. Display tiff image
    By rajg in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2012, 06:50
  2. Replies: 11
    Last Post: 21st June 2011, 01:05
  3. TIFF image Format
    By dima in forum Qt Programming
    Replies: 7
    Last Post: 13th September 2010, 13:42
  4. Use QImageReader to test image files
    By jvillain in forum Qt Programming
    Replies: 1
    Last Post: 23rd March 2009, 10:05
  5. Replies: 2
    Last Post: 7th November 2006, 12:49

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.