opengl - Qt Use ShaderEffect for QImage rendering -
i wondering if possible via qt quick or c++ use shader effect on image , save effect applied.
the reason doing achieve opengl assisted image effect manipulation (ie. emboss, pixelize, etc)
i tried this:
import qtquick 2.4 import qtquick.controls 1.3 import qtquick.dialogs 1.2 applicationwindow { id: root title: qstr("hello world") width: 640 height: 480 visible: true image { id: effectimage width: 200 height: 200 sourcesize.width: width sourcesize.height: height anchors.centerin: parent source: "qrc:/myimage.png" layer.enabled: true layer.effect: shadereffect { fragmentshader: " uniform lowp sampler2d source; // item uniform lowp float qt_opacity; // inherited opacity of item varying highp vec2 qt_texcoord0; void main() { lowp vec4 p = texture2d(source, qt_texcoord0); lowp float g = dot(p.xyz, vec3(0.344, 0.5, 0.156)); gl_fragcolor = vec4(g, g, g, p.a) * qt_opacity; }" } } button { id: grabit anchors.top: effectimage.bottom text: qstr("grab") onclicked: { effectimage.grabtoimage(function(result) { console.debug("hallo"); result.savetofile("test.jpg","jpg"); }); } } }
applying simple grayscale effect on image. works on-screen, grabtoimage() not apply effect.
is there way this?
ok easy, solved problem wrapping image item element , grabbing image instead:
import qtquick 2.4 import qtquick.controls 1.3 import qtquick.dialogs 1.2 applicationwindow { id: root title: qstr("hello world") width: 640 height: 480 visible: true item { id: effectimage width: 200 height: 200 anchors.centerin: parent image { anchors.fill: parent sourcesize.width: width sourcesize.height: height source: "qrc:/myimage.png" layer.enabled: true layer.effect: shadereffect { fragmentshader: " uniform lowp sampler2d source; // item uniform lowp float qt_opacity; // inherited opacity of item varying highp vec2 qt_texcoord0; void main() { lowp vec4 p = texture2d(source, qt_texcoord0); lowp float g = dot(p.xyz, vec3(0.344, 0.5, 0.156)); gl_fragcolor = vec4(g, g, g, p.a) * qt_opacity; }" } } } button { id: grabit anchors.top: effectimage.bottom text: qstr("grab") onclicked: { effectimage.grabtoimage(function(result) { console.debug("hallo"); result.savetofile("test.jpg","jpg"); }); } } }
hope helps else :-)
Comments
Post a Comment