Passing QImage data from a text file or data stream
-
I am building some functions to handle data from multiple imaging devices, I have written functions to collected data and it returns the data in the format:
x-coord y-coord value
0 0 2001
0 1 1999
...I can parse this data in C++ and would like to build a GUI to visualise this image. As I understand, I should use QImage. From the documentation it looks as if I need to use QImage::load() or QImage::loadFromData(), but they read binary data and my data is not in that form.
Would anyone be able to point me in the right direction? Thanks!
-
No, QImage is not smart enough to detect your custom format (here you can find a list of supported formats). just create a QImage with the resulting size and then iterate x and y and call
setPixel(x,y,value)
to build it@VRonin said in Passing QImage data from a text file or data stream:
No, QImage is not smart enough to detect your custom format (here you can find a list of supported formats). just create a QImage with the resulting size and then iterate x and y and call
setPixel(x,y,value)
to build itEven so it's probably the right way to do it, this sounds like it would take, figuratively, forever to create the QImage that way.
-
I am building some functions to handle data from multiple imaging devices, I have written functions to collected data and it returns the data in the format:
x-coord y-coord value
0 0 2001
0 1 1999
...I can parse this data in C++ and would like to build a GUI to visualise this image. As I understand, I should use QImage. From the documentation it looks as if I need to use QImage::load() or QImage::loadFromData(), but they read binary data and my data is not in that form.
Would anyone be able to point me in the right direction? Thanks!
@jamie
the most reusable way would probably be to create a custom imageformat plugin by implementing QImageIOPlugin interface (in a custom Qt plugin).
Take this a reference for example.In the plugin you still need to create a QImage at some point (in QImageIOHandler::read(), to be specific). But i wouldn't use QImage::setPixel() for that but write the (qRgb-)data directly into memory by using QImage::bits() then.