不透明蒙版的动态绘制
我有两张背景图片,一张是模糊的,另一张是相同的图片,但色彩更丰富。 默认背景图像是模糊的。 当我移动光标时,我想将背景图像从模糊更改为彩色, 但仅限于光标周围的圆圈内, 当我向前移动光标时,更改后的背景保留在光标周围的圆圈之前所在的位置。 (就像用硬币刮彩票一样) 我想我必须处理 MouseMove 事件,并使用 MouseEventArgs 光标位置, 但我无法通过,我真的需要帮助! 提前致谢!
I've got two background pictures, one is blurry, the other one is the same picture, but more colorful.
The default background image is the blurry one.
When I move the cursor, I'd like to change the background image from the blurry to the colorful one,
but only in a circle around the cursor,
and when I move the cursor forward, the changed background stays where the circle around the cursor went earlier.
(like when you scratch a lottery ticket with a coin)
I think I have to handle the MouseMove event, and use the MouseEventArgs cursor position,
but I cannot go through, and I really need help!
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想尝试遵循以下路径:
向页面添加
Canvas
,其大小与两个图像相同创建椭圆形状的剪切路径(
)并将其放置在图像之外,在画布中将首先在画布上放置“模糊图像”(如下),然后放置“清晰图像”,填充整个画布。
让椭圆成为“清晰图像”的剪贴蒙版(使用
Image.Clip
或YourUIElement.Clip
(参考MSDN)用鼠标光标移动椭圆。代码可能如下所示(注意:我没有测试代码):
-
如果这有效,您可以增加视觉设计,在
MouseEnter
/MouseLeave
等上添加动画。You might want to try following this path:
Add a
Canvas
to your page, with the same size as both of your imagesCreate a clipping path in the shape of an ellipse (
<Ellipse ...>
) and position it outside of your image, in the canvasPut the "blurry image" on your canvas first (below), and then the "sharp image", filling the whole canvas.
Let the ellipse be the clipping mask of your "sharp image" (using
Image.Clip
orYourUIElement.Clip
(reference on MSDN)Move your ellipse with the mouse cursor. The code might look like this (note: I didn't test the code):
-
If this works, you can increment your visual design adding animations on
MouseEnter
/MouseLeave
, etc.