Windows phone 7 收缩时调整矩形元素的大小(手势)
我正在尝试裁剪图像。为了选择裁剪区域,我使用了一个矩形元素。 矩形的初始宽度和高度分别设置为100。挤压时,矩形的大小将增大。如何获得放大后的矩形的大小 我使用的代码如下:Windows phone 7 收缩时调整矩形元素的大小(手势),windows-phone-7,Windows Phone 7,我正在尝试裁剪图像。为了选择裁剪区域,我使用了一个矩形元素。 矩形的初始宽度和高度分别设置为100。挤压时,矩形的大小将增大。如何获得放大后的矩形的大小 我使用的代码如下: private void GestureListener_PinchDelta(object sender, PinchGestureEventArgs e) { ImageTran
private void GestureListener_PinchDelta(object sender, PinchGestureEventArgs e)
{
ImageTransformation.ScaleX = _initialScale * e.DistanceRatio;
ImageTransformation.ScaleY = ImageTransformation.ScaleX;
cropRectangle.Width = cropRectangle.Width + e.DistanceRatio;
cropRectangle.Height = cropRectangle.Height + e.DistanceRatio;
}
我无法获得放大矩形的大小渲染Transforms不会更改控件的宽度和高度,因为它只影响渲染。不确定是否有更好的方法,但可以使用原始大小和比例因子简单地计算渲染大小 这是一个非常基本的例子 xaml
<Canvas x:Name="cnv" Grid.Row="1">
<Rectangle Canvas.Top="150" Canvas.Left="150"
Width="200" Height="200" x:Name="myrect"
Fill="AliceBlue"
ManipulationStarted="myrect_ManipulationStarted"
ManipulationDelta="myrect_ManipulationDelta"
ManipulationCompleted="myrect_ManipulationCompleted">
</Rectangle>
</Canvas>
我必须乘以比例因子,我犯了一个错误,把它和距离比相加。谢谢。。
public MainPage()
{
InitializeComponent();
transformGroup = new TransformGroup();
translation = new TranslateTransform();
scale = new ScaleTransform();
transformGroup.Children.Add(scale);
transformGroup.Children.Add(translation);
myrect.RenderTransform = transformGroup;
}
private TransformGroup transformGroup;
private TranslateTransform translation;
private ScaleTransform scale;
private void myrect_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
//change the color of the Rectangle to a half transparent Red
myrect.Fill = new SolidColorBrush(Color.FromArgb(127, 255, 0, 0));
}
private void myrect_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
translation.X += e.DeltaManipulation.Translation.X;
translation.Y += e.DeltaManipulation.Translation.Y;
//Scale the Rectangle
if (e.DeltaManipulation.Scale.X != 0)
scale.ScaleX *= e.DeltaManipulation.Scale.X;
if (e.DeltaManipulation.Scale.Y != 0)
scale.ScaleY *= e.DeltaManipulation.Scale.Y;
}
private void myrect_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
myrect.Fill = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
Debug.WriteLine(myrect.Width * scale.ScaleX);
Debug.WriteLine(myrect.Height * scale.ScaleY);
}