QML Image and raw 8-bit Image data
-
Hello all!
So I have a question. I have an 2D array [x,y] of RGB values [0-255,0-255,0-255]. So three channels of 8-bit color data.
I want to be able to pass that data to QML in some way. The thing is, I have no idea where to even begin with this (so my apologies if this post is a bit vague).The 2D array (Let's call it 'pix_buf') is a 512x512 2D array that looks like a little like this (I put in leading zeros in the example to help line up the matrix):
0 1 2 509 510 511 0 [000,000,000], [000,020,040], [020,090,100] ..., [212,111,090], [060,040,020], [101,211,100] 1 [200,100,090], [020,121,033], [100,023,039] ..., [212,100,020], [100,100,100], [090,010,010] ... 511 [201,211,121], [090,020,090], [021,011,100] ..., [030,010,010], [050,120,255], [255,255,255]
I have in QML an image such as:
Image { id: image_data ObjectName: "image_data" fillMode Image.PreserveAspectFit source: "sample.png" }
So I have an image that is part of a ApplicationWindow object in QML. I'm using PyQt5 (it's okay if your answers are in C++ I can do the conversion over).
In short, I have a that 2D, 8-bit RGB value array and I would like to pass on that data, or somehow be able to reconstruct it so that it only exists in memory. I want to avoid writing .tif, .png, or .jpg files to a file system so that QML can pick up and read. Is there any way to call on this Image object and pass in that data in one form or another instead of writing it to a file and then once written have PyQt5 or C++ read in that written file? It just seems like a lot of overhead.
So right now I have this:
[Read in raw data - make 2D array] -> [export array to image file] -> [update QML image with PyQt5 to read new exported image file]I would like this:
[Read in raw data - make 2D array] -> [update QML with PyQt5 display array as image]in PyQt5, I already declared the object name and associated "image_data" to a PyQt object. I even created some get/set functions in the QML file to get and set attributes of that QML image such as its source, but again, I don't want the source to be reading from a file in the file system. Should I use something else other than QML's image object, Qimage I have seen people use that to read in data? (I just dont want to manually copy RGB values to a new array using an x and y nested for loop, it's to CPU costly)
below is the QML Image object in PyQt5:
self.display = self.win.findChild(QObject, 'image_data')
Where 'self.display' is the QML image and 'self.win' is the ApplicationWindow QML object.
If you want more information, please ask. I know it's a bit vague, but I'm "shooting in the dark" so-to-speak. Thank you everyone for your patience and time! And again - if you'd rather reply with C++ that's a-okay, I can work with that.
-
This might be the start of what I am looking for?
https://stackoverflow.com/questions/47502885/qquickimageprovider-pyqt5Use an image provider, load in an array of bytes and associate it that image provider with the QML 'image_data' ?