开发者

How to make some layer mask in Silverlight?

开发者 https://www.devze.com 2023-02-24 13:40 出处:网络
I have an image object and a rectangle object. Now I want to be the image to be only visible where th开发者_StackOverflow中文版e rectangle is, everything else should have an opacity of 0.5 - the resul

I have an image object and a rectangle object. Now I want to be the image to be only visible where th开发者_StackOverflow中文版e rectangle is, everything else should have an opacity of 0.5 - the result should look something simliar to the following:

How to make some layer mask in Silverlight?

When I set the opacity of the rectangle to 0.5 the effect is the antipode - so how could I realize it as shown in the image? Size and position of the rectangle is changed by code-behind, but that shouldn't make any differences...

All hints / answeres appreciated :)


If you want to add an opaque mask to partially hide your image outside of a rectangle, it's rather easy.

<Grid>
  <Image Source="myImage.jpg" Opacity="0.5/>
  <Image Source="myImage.jpg" >
   <Image.Clip>
     <RectangleGeometry Rect="x,y,w,h"/>
   </Image.Clip>
  </Image>

</Grid>

Where x,y,w and h are your rectangle position and size (see MSDN). If you want to move the visible portion around, set the Clip property by code.

If you want to add the "black stroke effect", you could simply add a Rectangle with position and size matching those of your clipping path after the second image in your grid.

Do you want more infos?

0

精彩评论

暂无评论...
验证码 换一张
取 消