Request: Keep ratio
I want keep ratio 1x1 at cropped area. I changed Corner_PointerMoved function. it works a bit. but it doesn't work when i leave cropped area. How can i keep ratio 1x1? Here is the code
`private void Corner_PointerMoved(object sender, PointerRoutedEventArgs e) { Windows.UI.Input.PointerPoint pt = e.GetCurrentPoint(this); uint ptrId = pt.PointerId;
if (pointerPositionHistory.ContainsKey(ptrId) && pointerPositionHistory[ptrId].HasValue)
{
Point currentPosition = pt.Position;
Point previousPosition = pointerPositionHistory[ptrId].Value;
var control = (sender as ContentControl);
int multiplying = 1;
if (control.Name == "PART_TopRightCorner" || control.Name == "PART_BottomLeftCorner")
{
multiplying = -1;
}
double xUpdate = currentPosition.X - previousPosition.X;
double yUpdate = multiplying * xUpdate;
var side = Math.Max(Math.Abs(xUpdate), Math.Abs(yUpdate));
this.selectedRegion.UpdateCorner((sender as ContentControl).Tag as string,
side * Math.Sign(xUpdate),
side * Math.Sign(yUpdate));
pointerPositionHistory[ptrId] = currentPosition;
}
e.Handled = true;
}`

@XamlBrewer Can you let me know where should i change to restrict to only square cropping rectangle?
Tomorrow I will create a branch with an almost working version of a fixed-ratio image cropper.
have you created a sample for fixed ratio?
Please check this branch: https://github.com/XamlBrewer/UWP-ImageCropper-/tree/fixed-ratio
Hi,
Thanks for your reply. But, In you sample, the ratio is maintained only if we drag from bottom-right corner. I want to drag from any corner while preserving the ratio(for eg: 4:3). Any idea?
Regards, Prashant
I did not check your code completely. But I think there will be a problem in resizing when I move corner vertically. In this case, there is no horizontal change, so leftUpdate is 0 and then topUpdate will be calculated to be 0 as well.