C# .net 中的放大镜

发布于 2024-11-06 15:01:43 字数 92 浏览 1 评论 0原文

我在面板中绘制了图像。当我选中“放大”复选框并将鼠标光标放在面板上时,覆盖光标的矩形区域应该被放大。我该怎么做呢?我搜索了Codeproject.com,没有找到这样的。

I have drawn an image in a panel. When I check a 'Magnify' check box and place mouse cursor over the panel, the rectangle area covering the cursor should be magnified. How can I do it? I searched Codeproject.com and did not find such one.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

塔塔猫 2024-11-13 15:01:43

这是在 WPF 中执行此操作的方法

在 WinForms 中,这并不那么容易,但仍然可行。您必须在图片框顶部添加控件并使用光标移动它(并调整放大镜中图像的原点以进行移动)。

This is how you do this in WPF

In WinForms it is not that easy but still doable. You have to add the control on top of the picturebox and move it around with the cursor (and adjust the origin in of the image in the magnifier to move along).

浅浅 2024-11-13 15:01:43

我很久以前就做过类似的事情,但我不知道这是否是最好的方法或今天是否存在更好的方法。我通过放大强度确定了我的观看区域到各个像素的映射。常规图像上的每个像素代表一个不同大小的小矩形,具体取决于放大级别,并且它也具有与像素相同的颜色属性。

我计算出我的查看区域可以容纳多少个像素矩形,然后用它来计算原始快照矩形的大小。我从上到左阅读每个像素,直到到达左下角,并在快照中为每个像素创建这些矩形,并将它们一个接一个地放置在查看区域图像中。

它工作得很好而且速度相当快,但我必须双缓冲查看图像面板才能获取更新。这种方法的一个大问题是我无法缩小原始图像。

就像我说的,我确信他们是更好的方法来做到这一点,因为我只是在最后一刻把一些东西放在一起。

I did something similar a long time ago but I don't know if it was the best approach or better approaches exist today. I determined a mapping of my viewing area by magnification strength to individual pixels. Each pixel on the regular image represented a small Rectangle of varying size depending on magnification level and it had the same color attribute as the pixel as well.

I figured out how many Pixel Rectangles I could fit in my viewing area and then used that to figure out the snapshot rectangle size on the original. I read through every pixel top to left until I reached bottom left, and in the snapshot creating these rectangles for each pixel and placing them in the viewing area image one after the other.

It worked decently well and was pretty fast but I had to double buffer the viewing image panel to get updates. A big problem with this approach was that I couldn't zoom out from the original.

Like I said I am sure their are better ways to do this as I was just whipping something together at the last minute.

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