PDA

View Full Version : Why show the incorrect TIFF image by QImageReader Read



johenny
7th April 2013, 11:03
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?



QImageReader imageReader( mstrImagePath );
QImage pic = imageReader.read();
painter->drawImage( QRectF(0, 0, pic.width(), pic.height()), pic );

wysota
7th April 2013, 11:07
Does QImage::width() and QImage::height() return proper values for your "bad" images?

johenny
8th April 2013, 03:38
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.

889788958896

ChrisW67
8th April 2013, 04:12
How are you resizing the image? What are you painting on to? Where is the painting code?

johenny
8th April 2013, 04:33
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?

wysota
8th April 2013, 05:15
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?

ChrisW67
8th April 2013, 05:16
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?

johenny
8th April 2013, 07:13
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!

wysota
8th April 2013, 07:38
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?

johenny
8th April 2013, 08:08
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?

ChrisW67
8th April 2013, 09:12
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.



#include <QtGui>
#include <QDebug>

class View: public QGraphicsView
{
Q_OBJECT
public:
View(QGraphicsScene *scene, QWidget *p = 0): QGraphicsView(scene, p)
{
}
protected:
void drawBackground(QPainter *painter, const QRectF &rect)
{
static const QImage pic("test.tif");
qDebug() << pic.size() << rect << viewport()->size();
painter->drawImage(QRectF(0.0, 0.0, pic.width(), pic.height()), pic);
}
};

int main(int argc, char **argv)
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.addText("Hello, world!");

View v(&scene);
v.show();
return app.exec();
}
#include "main.moc"

wysota
8th April 2013, 10:01
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.

johenny
8th April 2013, 10:08
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?


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.



#include <QtGui>
#include <QDebug>

class View: public QGraphicsView
{
Q_OBJECT
public:
View(QGraphicsScene *scene, QWidget *p = 0): QGraphicsView(scene, p)
{
}
protected:
void drawBackground(QPainter *painter, const QRectF &rect)
{
static const QImage pic("test.tif");
qDebug() << pic.size() << rect << viewport()->size();
painter->drawImage(QRectF(0.0, 0.0, pic.width(), pic.height()), pic);
}
};

int main(int argc, char **argv)
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.addText("Hello, world!");

View v(&scene);
v.show();
return app.exec();
}
#include "main.moc"



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.

wysota
8th April 2013, 10:57
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.

johenny
8th April 2013, 11:03
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.

wysota
8th April 2013, 11:31
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().

ChrisW67
9th April 2013, 00:46
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 (http://www.wikipedia.org/wiki/Tagged_Image_File_Format) 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.

johenny
9th April 2013, 03:23
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 ?

johenny
17th April 2013, 03:59
Add CxImage library to slove this problem. The reason maybe the image had not been flatted.
Thanks to ChrisW67 and wysota.