在图片框或其他控件中显示的图像上实现对vb.net的滑动和缩放。 [英] Implement swipe and zoom in vb.net on images displayed in a picturebox or other control.

查看:233
本文介绍了在图片框或其他控件中显示的图像上实现对vb.net的滑动和缩放。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用了vb.net多年,并开发了许多应用程序供我自己使用。

我甚至将其中的一部分迁移到Android,以便在我的三星手机和我的手机上使用儿童Android平板电脑。

其中三个应用程序与家庭照片的管理和显示有关。

我最近买了一本Surface Book,我觉得它很容易复制用于操作照片的Android / IOS界面。向左和向右滑动以进行下一个和上一个。捏手势放大和缩小。



我在Windows 10上使用Visual Studio Cummunity 2015



我曾假设PictureBox控件的最新版本具有滑动(或滑动或轻弹)和缩放事件。但没有。

我认为扩展控件会比较简单,就像我在Android中一样将这些功能添加到ImageView。



我在windows.ui.input命名空间中找到了GestureRecognizer类,但这似乎只能在通用Windows平台(UWP)下工作,这需要进行大量的重新设计。



有没有办法在Visual Studio下开发的传统VB.NET应用程序中的图片框上实现滑动和缩放缩放?



我尝试过:



我搜索了各种论坛。我在UWP VB下使用XAML构建了一个小型测试应用程序,但它意味着重建我在XAML中的所有表单以及可能还有其他我尚未发现的重大更改。

I have used vb.net for years and have developed a number of applications for my own use.
I have even migrated some of them to Android for use on my Samsung phone and my grand-childrens Android tablets.
Three of these apps relate to the management and display of family photos.
I have recently bought a Surface Book and I thought it would be easy to replicate the Android / IOS interface for manipulating photos. Swipe left and right for next and previous. Pinch gestures to zoom in and out.

I am using Visual Studio Cummunity 2015 on Windows 10.

I had assumed that the latest version of the PictureBox control would have Swipe (or Slide or Flick) and Zoom events. But no.
I thought it would be relatively easy to extend the control as I did in Android to add these functions to ImageView.

I found the GestureRecognizer class in the windows.ui.input namespace but this appears to only work under the Universal Windows Platform (UWP) which would require a substantial redesign.

Is there any way to implement swipe and pinch zoom on a picturebox in a conventional VB.NET application developed under Visual Studio?

What I have tried:

I have searched various forums. I have built a small test application under UWP VB with XAML which works, but implies rebuilding all my forms in XAML and probably other major changes I have not yet discovered.

推荐答案

不,你必须从头开始实现这样的手势识别。这不应该太难。一个控件需要一个状态机分阶段刷卡:1)等待; 2)按下鼠标键; 3)鼠标移动足够的距离;检测到滑动方向; 4)鼠标按钮上升,滑动完成(这里你调用你的滑动事件)。



所以,基本上,你的状态机将是阶段的枚举并检测到滑动方向;您可以将一个枚举类型上的所有这些状态与使用|组合相位和检测到的方向的成员组合(OR)运算符,它们整个机器数据集只是一个字段。现在,您处理低级鼠标事件,这可能导致状态机更改状态 MouseUp MouseDown 的MouseMove 。此算法可以使用 System.Windows.Forms ,WPF,ASP.NET,Silverlight等实现,因此请自行查找API元素的链接。最重要的是,为 Swipe 事件创建自己的事件参数类型,并为自定义控件创建公共事件实例。应在滑动检测的最后阶段调用此事件。这个想法是这样的:您应该按照上述顺序预期鼠标事件。以预期顺序调用的任何鼠标事件(可能还有一些其他事件)都会通过设置初始状态来中断相序;成功滑动识别和调用事件后,状态也会设置为初始状态值。重要的一点是在一次滑动中距离不足。所需的最小距离应该是应用程序的可选值。我建议通过不足的距离滑动也会将状态设置为其初始值,而不是等待下一个 MouseMove 事件中的滑动继续。这种简单的算法将过滤掉不够长且不够快的滑动或者以不能将其解释为在某个方向上滑动的角度执行的滑动。此外,您只能考虑水平和垂直滑动(正好有4个方向);你应该只过滤滑动,其中这些方向之一的坐标差异在垂直方向上明显占主导地位。识别方向的准确性也是一种选择。有了一些经验,你可以找到真实的选项。



这是你可以轻松实现的功能的初步设计。



对于缩放,该方法取决于您使用的UI库。解决方案非常明显但不同。如果你澄清并要求我详细说明,我也会尝试帮助它。



为了以防万一,看看我过去的答案,但不要指望最终解决方案:

在C#.net鼠标滚轮中缩放图像 [ ^ ],

在流中读取Big Tiff和JPEG文件(>(23000 x 23000)pix)。并实时显示部分内容。 [ ^ ]。

对于WPF,缩放可以与以下一项或两项一起使用:

UIElement.RenderTransform Property(System.Windows) [ ^ ] ,

Viewbox类(System.Windows.Controls) [ ^ ]。



-SA
No, you have to implement such gesture recognition from scratch. It should not be too hard. A control need to have a state machine with phased of swiping: 1) waiting; 2) mouse button pressed down; 3) mouse moved by a sufficient distance; direction of swipe detected; 4) mouse button goes up, swipe complete (here you invoke your swipe event).

So, basically, your state machine would be the enumeration of the phases and detected swipe direction; you can combine all these states on one enumeration type with members combining phase and detected direction using | (OR) operators, them the whole machine data set would be just one field. Now, you handle "low-level" mouse events which can cause the state machine to change state MouseUp, MouseDown, MouseMove. This algorithm can be implemented with System.Windows.Forms, WPF, ASP.NET, Silverlight, and so on, so please find the links to the API elements by yourself. On top of that, create your own event arguments type for your Swipe event and create a public event instance for your custom control. This event should be invoked on the last phase of swipe detection. The idea is this: you should expect mouse events in the order described above. Any mouse event (and perhaps some other events) invoked not in the expected order break the phase sequence by setting the initial state; after successful swipe recognition and invocation of your event, the state also set to initial state value. Important point is "insufficient distance" in one swipe. The required minimal distance should be an optional value for your application. I suggest that a swipe by insufficient distance also sets the state to its initial value, without trying to wait for "continuation" of the swipe in next MouseMove event. This simple algorithm will filter out swipes which are not long and fast enough or those performed at an angle which cannot interpreted it as a swipe at certain direction. Also, you can consider only horizontal and vertical swipes (having exactly 4 directions); than you should filter only the swipes where the difference on coordinates in one of these directions clearly dominates over the perpendicular direction. The accuracy of recognition of the direction can also be an option. With some experience, you can figure out realistic set of options.

This is preliminary design of the feature which you can easily implement.

For zoom, the approach depends on the UI library you are using. The solutions are pretty obvious but different. If you clarify on that and ask me to elaborate on that, I'll try to help with it, too.

Just in case, look at my past answers, but don't expect a final solution:
Zoom image in C# .net mouse wheel[^],
Read Big Tiff and JPEG files (>(23000 x 23000) pix) in a stream. And display part of it to the screen in realtime.[^].
For WPF, zooming can be used with one or two of these things:
UIElement.RenderTransform Property (System.Windows)[^],
Viewbox Class (System.Windows.Controls)[^].

—SA


这篇关于在图片框或其他控件中显示的图像上实现对vb.net的滑动和缩放。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆