I have been working on a project where I need to apply image masking that applies an effect like this:
Pic1: https://i.stack.imgur.com/6zI2x.jpg
Pic2: https://i.stack.imgur.com/z7IVX.jpg
Mask frame: https://i.stack.imgur.com/3syEm.jpg
Desired effect: https://i.stack.imgur.com/t2kO5.jpg
I got it to work by using OpacityMask however to do that I had to use some photoshop and edit my mask frame image. I need to apply this affect to multiple mask frames with different shapes therefore using photoshop to edit all of them seem troublesome. Moreover, the inside of the mask frame images arent all transparent either.
Is there any ideas you can give me to solve this issue without using any pre photoshoping each mask frame images. I tried to look into ShaderEffect but I could not really understand how I should use it for my purpose. Moreover I searched for a OpacityMask like effect but working only on part of the mask image which has a specific color/specific shaped area. However, I could not find any.
2
Answers
If you know that the geometry of your picture frame is just a rectangle, we can just create a rectangular mask aligned within your picture frame. I worked out that your picture frame was 410×500 pixels and decided to shrink it to 50% i.e. 205×250 pixels. At that scale, I worked out that your picture frame had a border size of about 18 pixels. So I created an inner rectangle based on those dimensions and used that rectangle for the
OpacityMask
maskSource
:ShaderEffect
appears to be the only option, considering what you said in the comments that the frame shape could be anything.The code examples below show how to solve your issue with
ShaderEffect
.QML code
The only property on the QML side is the
rect
, which defines thex
,y
,width
, andheight
of the frame, which are scaled down to between0
and1
.shader.glsl
I discovered that the saturation inside the image is very different from other areas after using a color picker in different points of the frame image.
So, in order to decide where to mask in the image, I used saturation.
Note
You can also change the last line of code if you want the frame’s shadow to cover your image.
Result