Thanks for reply Gunnar, I can safely use this technique now. Regards, Manish
On Sun, Sep 14, 2014 at 1:28 PM, Gunnar Sletta <gun...@sletta.org> wrote: > Yeah, it looks like this will work quite well :) > > Using either ShaderEffectSource or turning the item into a texture > provider using Item::layer::enabled is the way to do this prior to Qt 5.4. > > cheers, > Gunnar > www.sletta.org > > On 13 Sep 2014, at 16:28, manish sharma <83.man...@gmail.com> wrote: > > > Hi, > > > > I found a way to get the QImage of an QQuickItem, I am aware of > QQuickWindow::grabImage and QQuickItem::grabToImage will be available in > Qt5.4. So far i am getting correct QImage and it seems to work quite well. > I want to know what i am doing is correct. > > > > Flow:- > > - create ShaderEffectSource > > - on ShaderEffectSource::scheduledUpdateCompleted signal hook to > afterRendering of window > > - inside afterRendering get the > ShaderEffectSource::textureProvider::texture and use glGetTexImage to get > an QImage. > > > > Code:- > > C++ > > QuickWindow() > > { > > ..... > > m_snapshotItem = root->findChild<QQuickItem*>("snapShotItem"); > > connect (m_snapshotItem, SIGNAL(scheduledUpdateCompleted()), > this, SLOT(takeSnapshot())); > > } > > > > private slots: > > void takeSnapshot() > > { > > connect(this, SIGNAL(afterRendering()), this, SLOT(getImage()), > Qt::DirectConnection); > > } > > > > void getImage() > > { > > qDebug() << "taking snapshot..!"; > > disconnect(this, SIGNAL(afterRendering()), this, > SLOT(getImage())); > > QSGTexture *texture = > m_snapshotItem->textureProvider()->texture(); > > texture->bind(); > > GLint internalFormat; > > glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, > GL_TEXTURE_COMPONENTS, &internalFormat); // get internal format type of GL > texture > > QImage img(texture->textureSize(), QImage::Format_RGBX8888); > > glGetTexImage(GL_TEXTURE_2D, 0, internalFormat, > GL_UNSIGNED_BYTE, img.bits()); > > img.save("c:\\temp\\snapshot.bmp"); > > } > > > > QML > > Item { > > anchors.fill: parent > > > > Rectangle { > > id: rect > > anchors.fill: parent > > color: "green" > > } > > > > ShaderEffectSource { > > objectName: 'snapShotItem' > > anchors.fill: rect > > live: false > > recursive: false > > sourceItem: rect > > } > > } > > > > Regards, > > Manish > > > > _______________________________________________ > > Interest mailing list > > Interest@qt-project.org > > http://lists.qt-project.org/mailman/listinfo/interest > >
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest