Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 1.69 KB | None | 0 0
  1. Item {
  2.     id: mainpage
  3.     Rectangle {
  4.         width: 200
  5.         height: 200
  6.  
  7.         color: "transparent"
  8.  
  9.         //this Rectangle is needed to keep the source image's fillMode
  10.         Rectangle {
  11.             id: imageSource
  12.  
  13.             anchors.fill: parent
  14.             Image {
  15.                 anchors.fill: parent
  16.                 source: "qrc:/_84154370_facebook.jpg"
  17.  
  18.                 fillMode: Image.PreserveAspectCrop
  19.             }
  20.             visible: false
  21.  
  22.             layer.enabled: true
  23.         }
  24.  
  25.         Rectangle {
  26.             id: maskLayer
  27.             anchors.fill: parent
  28.             radius: parent.width / 2
  29.  
  30.             color: "red"
  31.  
  32.             border.color: "black"
  33.  
  34.             layer.enabled: true
  35.             layer.samplerName: "maskSource"
  36.             layer.effect: ShaderEffect {
  37.  
  38.                 property var colorSource: imageSource
  39.                 fragmentShader: "
  40.                    uniform lowp sampler2D colorSource;
  41.                    uniform lowp sampler2D maskSource;
  42.                    uniform lowp float qt_Opacity;
  43.                    varying highp vec2 qt_TexCoord0;
  44.                    void main() {
  45.                        gl_FragColor =
  46.                            texture2D(colorSource, qt_TexCoord0)
  47.                            * texture2D(maskSource, qt_TexCoord0).a
  48.                            * qt_Opacity;
  49.                    }
  50.                "
  51.             }
  52.  
  53.         }
  54.  
  55.         // only draw border line
  56.         Rectangle {
  57.             anchors.fill: parent
  58.  
  59.             radius: parent.width / 2
  60.  
  61.             border.color: "black"
  62.             border.width: 1
  63.  
  64.             color: "transparent"
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement