简体   繁体   English

光标后的UWP放大镜控件(工具)

[英]UWP Magnifier control (tool) that follows cursor

I am working on an assignment right now and was asked to create an app to select an area on image with ability to magnify a part of the image around cursor. 我现在正在做一个作业,被要求创建一个应用程序来选择图像上的区域,并能够放大光标周围图像的一部分。

Right now I stuck on the magnifier part. 现在我卡在放大镜部分。 There is a Magnifier control in WPF, but how about UWP? WPF中有一个放大镜控件,但是UWP呢? Has anyone had any experience creating magnifier in UWP? 有没有人有过在UWP中创建放大镜的经验?

SO far I've found this, but UWP has different API's: http://csharphelper.com/blog/2015/06/zoom-and-crop-a-picture-in-c/ 到目前为止,我已经找到了,但是UWP具有不同的API: http : //csharphelper.com/blog/2015/06/zoom-and-crop-a-picture-in-c/

My logic is: 1. Draw circle around the cursor and re-draw it every time the cursor moves. 我的逻辑是:1.在光标周围绘制一个圆圈,并在每次光标移动时重新绘制。 2. Take a screenshot (render) specified area around it 3. Magnify the are 4. Fill the circle with the magnified image (Bitmap) 2.截取屏幕快照(渲染)指定区域3.放大区域4.用放大的图像(位图)填充圆圈

Any tips or suggestions would be much appreciated. 任何提示或建议将不胜感激。 Thank you 谢谢

  1. Draw circle around the cursor and re-draw it every time the cursor moves. 围绕光标绘制一个圆圈,并在每次光标移动时重新绘制。

You could register the PointerMoved event for your panel(eg, Canvas) and get current pointer by using the following method: 您可以为面板(例如Canvas)注册PointerMoved事件,并使用以下方法获取当前指针:

private void Canvas_PointerMoved(object sender, PointerRoutedEventArgs e)
{
    var pointer = e.GetCurrentPoint(sender as UIElement);
}

And then, you could add a Ellipse on it and set its position by current pointer. 然后,您可以在其上添加一个Ellipse并通过当前指针设置其位置。

  1. Take a screenshot (render) specified area around it 截取屏幕快照(渲染)指定区域

You could use RenderTargetBitmap class APIs to render specific area. 您可以使用RenderTargetBitmap类API来渲染特定区域。

  1. Magnify the are 放大

You could resize the rendertargetbitmap. 您可以调整rendertargetbitmap的大小。 Check this thread How to Resize the RenderTargetBitmap . 检查此线程如何调整RenderTargetBitmap的大小

  1. Fill the circle with the magnified image (Bitmap) 用放大的图像(位图)填充圆圈

After you get the final rendertargetbitmap, you could use it to make a ImageBrush , then you could specify this ImageBrush to the Ellipse's Fill property like the following: 在获得最终的rendertargetbitmap之后,可以使用它制作一个ImageBrush ,然后可以将此ImageBrush指定给Ellipse的Fill属性,如下所示:

ellipse.Fill = new ImageBrush() { ImageSource = renderTargetBitmap};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM