I'm surprised that I'm doing this, however the thread has come to such point that I can't see how any progress can be made.
Two facts:
1. there is this strange QImage::pixel() call that surprisingly according to the documentation returns the colour value of a particular pixel of the image.
2. There is this weird QFile::write() function where the name suggests that it writes something in a file.
Based on those two facts it should be trivial to iterate over the rows and columns of the image, retrieve pixel colour and store it in a file. The only difficulty is to decide about the way the colour should be stored. Let's start it with the loop itself, shall we?
for(int row = 0; row < image.height(); ++row) {
for(int col = 0; col < image.width(); ++col) {
QRgb px = image.pixel(col, row);
}
}
for(int row = 0; row < image.height(); ++row) {
for(int col = 0; col < image.width(); ++col) {
QRgb px = image.pixel(col, row);
}
}
To copy to clipboard, switch view to plain text mode
The next step is to be able to write something in a file, for that the file needs to be open. QFile docs contains an example how to open a text file for reading so your homework is to convert the example to open the file for writing.
Finally you have to write the pixel data by putting appropriate code in the for loop from the snippet above. I have no idea what format you need the data to be and it seems you didn't bother thinking about it so far so now sit back, relax, close your eyes and think about it. Then implement it using QFile::write() call.
If you cannot assemble a working code from all my hints, I strongly encourage you to switch jobs and become e.g. a fire fighter, farmer or car salesman.
Bookmarks