I have a QImage
(m_sourceImage) set with the Grayscale16
format.
I want this image to be converted to a QSGTexture
object to use it inside a QSGSimpleTextureNode
.
I tried to simply convert it with the following function: QQuickWindow::createTextureFromImage
// customItem.h
class OP_ImageViewer : public QQuickItem
{
OP_ImageViewer(QQuickItem *parent = nullptr) {setFlag(ItemHasContents, true);}
void setSourceImage(QImage i) {m_sourceImage = i;}
protected:
QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override;
private:
QImage m_sourceImage; // set outside the class
}
// customItem.cpp
QSGNode *customItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
{
QSGSimpleTextureNode* node = nullptr;
if(oldNode == nullptr)
InitializeNewNode(node); // create instance inside the given pointer
else
node = static_cast<QSGSimpleTextureNode*>(oldNode);
// update geometry
// set the texture to the node instance.
oldNode->setTexture(window()->createTextureFromImage(m_sourceImage, QQuickWindow::TextureIsOpaque));
// convert the image but truncate to 8 bit even if the image is a 16bit color format.
}
and this result in showing me the texture inside my custom qml but the pixel colors aren’t as precise as the QImage is.
Is there a method to create a QSGTexture with a 16 bit per color ?
adebono is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.