PDA

View Full Version : Almost reading QImage line by line, help me please.



newqtuser
18th July 2008, 06:12
Qt folks

Im trying to open a image file and display it line by line, after i get this working i want the line by line image data to be sent over the network to another system and have a qt app display this image data line by line on a QGraphicsScene. I think im almost there as far as showing the image data line by line, im just not sure if im getting the correct values in my test app, this is a small application can anyone tell me if im on the right track here?
I dont think this example is correct. At this point i just want line by line image data. Im not to worried about how to transfer it over the network yet, but i will need to send it in chunks of like 20 lines at a time over a socket. Here is a small example using a qt4 image.


#include <QApplication>
#include <QtGui>
#include <iostream>

using namespace std;

int main (int argc, char *argv[])
{
QApplication app (argc, argv);
QImage* pImage = new QImage("/images/qt4.jpg");

for ( int line = 0; line < pImage->height(); line++ )
{
for ( int pos = 0; pos < pImage->width(); pos++ )
{
cout << pImage->scanLine(line) << endl;
cout << pImage->scanLine(pos) << endl;
}
}
return app.exec ();
}

caduel
18th July 2008, 07:21
why do you iterate over columns (pos, width), too, if all you want is scan lines?

newqtuser
18th July 2008, 07:40
Well now im looking at it and asking my self the same question, how do i get a single line? Is that a single row?

caduel
18th July 2008, 08:25
I don't have used that stuff myself, but I would assume that

pImage->scanLine(line)
gives you the data for line i.

Note, however that this data in all probability will be binary.
Just writing it to cout (probably) won't work, unless you tell that stream to work on binary data.

newqtuser
18th July 2008, 14:22
Thanks caduel that worked. The main problem is that i was thinking it had to be harder then then that, qt just makes it simple.