【发布时间】:2014-10-22 14:03:34
【问题描述】:
再次大家好。最近我为 windows phone 8 设备创建了换脸应用程序,我设计了一个带有两个图像控件的页面
第一张图片作为背景,第二张图片控制是前景。
我已将“GestureListener”添加到我的第一个图像控件(背景)中,我必须使用“toolkit:GestureService.GestureListener”“捏、放大、缩小、拖动”该背景图像。
我做的一切都很好,就像我可以成功地捏、缩放、拖动图像一样......但是,
问题是“我无法从我触摸屏幕上的手指的任何地方捏或拖动图像”。所以捏缩放或拖动对我来说很难放大/缩小或拖动图像。,
但在 I-Phone/i-pad/i-pod 和所有 Android 设备中,我可以通过捏合来放大/缩小或从触摸屏幕上的任意位置拖动图像。,
就像我已经说过的,我的第一张图片是背景,可以添加手势控制,第二张图片是普通图片控制,不能缩放或拖动。,
这是我的代码。,
我的 XAML 代码:
<Grid x:Name="ContentPanel" Grid.RowSpan="2">
<Canvas x:Name="screenArea" Width="400" Height="580" >
<Image x:Name="myImage" Width="400" Height="580" RenderTransformOrigin="0.5, 0.5" CacheMode="BitmapCache" >
<Image.RenderTransform>
<TransformGroup>
<CompositeTransform x:Name="MyMustacheTransformation" />
</TransformGroup>
</Image.RenderTransform>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener PinchStarted="OnPinchStarted"
PinchDelta="OnPinchDelta"
DragDelta="OnDragDelta"/>
</toolkit:GestureService.GestureListener>
</Image>
<Image x:Name="frameImage" Width="400" Height="580" Stretch="Fill"/>
</Canvas>
</Grid>
而我的 pinch_start、Drag_delta、pinch_delta 的 CS 代码是
private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)
{
_initialAngle = MyMustacheTransformation.Rotation;
_initialScale = MyMustacheTransformation.ScaleX;
}
private void OnPinchDelta(object sender, PinchGestureEventArgs e)
{
MyMustacheTransformation.Rotation = _initialAngle + e.TotalAngleDelta;
MyMustacheTransformation.ScaleX = _initialScale * e.DistanceRatio;
MyMustacheTransformation.ScaleY = _initialScale * e.DistanceRatio;
}
private void OnDragDelta(object sender, DragDeltaGestureEventArgs e)
{
Image rect = sender as Image;
TranslateTransform transform = rect.RenderTransform as TranslateTransform;
MyMustacheTransformation.TranslateX += e.HorizontalChange;
MyMustacheTransformation.TranslateY += e.VerticalChange;
}
我希望你能理解我的要求,如果我的话不清楚,我很抱歉,
如果您已经在 Android/i-phone/pod/pad 设备上使用过换脸应用程序,则意味着他们可以轻松理解所期待的内容。
我的目标是:
“我可以通过捏合来放大/缩小,从触摸布局上的任何位置拖动图像.. 就像在 i-phone/pod/pad 和 android 设备中一样”
我已经挣扎了几个星期。请给出一些解决方案。
我你提供的任何示例代码意味着对我更有用。,
在此先感谢各位。,
【问题讨论】:
标签: c# wpf windows-phone-7 windows-phone-8 pinchzoom