Zvonimir Tusek

Zvonimir Tusek

  • NA
  • 9
  • 518

One image (kinect depth map) as opacityMask for other image

Oct 20 2019 3:37 PM
Hi, I have two image controls.
 
I want to use  Img1 as a OpacityMask of Img2. 
 
<Image Name="Img1" Width="500" Height="500"  />
<Image Name="Img2" Width="500" Height="500" Source="c:\temp\background.jpg"  />

Img1 -  image to apply mask to
Img2 - image to apply mask from
 
The source of Img1 is being read from kinect depth image: (I'm using OpenCV)
 
var depthBmp = depthFrame.SliceDepthImage((int)sliderMin.Value, (int)sliderMax.Value);
Image<Bgr, Byte> openCVImg = new Image<Bgr, byte>(depthBmp.ToBitmap());  outImg.Source = ImageHelpers.ToBitmapSource(openCVImg);
Img1.Source = ImageHelpers.ToBitmapSource(openCVImg);
-------------------------------------------------------------------------------------------
 
When I create ImageBrush, set its Imagesource to Img1.Source and apply OpacityMask from Brush, nothing happens, Img2 is shown without mask:
 
brush = new ImageBrush();
brush.ImageSource = Img1.Source;
Img2.OpacityMask = brush;
 
-----------------------------------------------------------------------------------------
For example, the mask is applied when I use BitmapImage as ImageSource of ImageBrush:
 
BitmapImage Img3 = new BitmapImage(new Uri(@"c:\temp\turtle.png", UriKind.Absolute));
brush = new ImageBrush();
brush.ImageSource = Img3.Source;
Img2.OpacityMask = brush;
--------------------------------------------------------------------------------------------
Tnx.
Zvonimir