不透明蒙版的动态绘制

发布于 2024-10-19 05:07:43 字数 207 浏览 1 评论 0原文

我有两张背景图片,一张是模糊的,另一张是相同的图片,但色彩更丰富。 默认背景图像是模糊的。 当我移动光标时,我想将背景图像从模糊更改为彩色, 但仅限于光标周围的圆圈内, 当我向前移动光标时,更改后的背景保留在光标周围的圆圈之前所在的位置。 (就像用硬币刮彩票一样) 我想我必须处理 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悟红尘 2024-10-26 05:07:43

您可能想尝试遵循以下路径:

  1. 向页面添加 Canvas,其大小与两个图像相同

  2. 创建椭圆形状的剪切路径()并将其放置在图像之外,在画布中

  3. 将首先在画布上放置“模糊图像”(如下),然后放置“清晰图像”,填充整个画布。

  4. 让椭圆成为“清晰图像”的剪贴蒙版(使用Image.ClipYourUIElement.Clip(参考MSDN)

  5. 用鼠标光标移动椭圆。代码可能如下所示(注意:我没有测试代码):

-

imageCanvas.MouseMove += imageCanvas_MouseMove;

private void imageCanvas_MouseMove(object sender, MouseEventArgs e)
{
    Point mousePosition = e.GetPosition();
    Canvas.SetTop(myEllipse, mousePosition.Y - myEllipse.ActualHeight / 2);
    Canvas.SetLeft(myEllipse, mousePosition.X - myEllipse.ActualWidth / 2);
}

如果这有效,您可以增加视觉设计,在 MouseEnter/MouseLeave 等上添加动画。

You might want to try following this path:

  1. Add a Canvas to your page, with the same size as both of your images

  2. Create a clipping path in the shape of an ellipse (<Ellipse ...>) and position it outside of your image, in the canvas

  3. Put the "blurry image" on your canvas first (below), and then the "sharp image", filling the whole canvas.

  4. Let the ellipse be the clipping mask of your "sharp image" (using Image.Clip or YourUIElement.Clip (reference on MSDN)

  5. Move your ellipse with the mouse cursor. The code might look like this (note: I didn't test the code):

-

imageCanvas.MouseMove += imageCanvas_MouseMove;

private void imageCanvas_MouseMove(object sender, MouseEventArgs e)
{
    Point mousePosition = e.GetPosition();
    Canvas.SetTop(myEllipse, mousePosition.Y - myEllipse.ActualHeight / 2);
    Canvas.SetLeft(myEllipse, mousePosition.X - myEllipse.ActualWidth / 2);
}

If this works, you can increment your visual design adding animations on MouseEnter/MouseLeave, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文