UWP-ImageCropper- icon indicating copy to clipboard operation
UWP-ImageCropper- copied to clipboard

Request: Keep ratio

Open hmtylmz opened this issue 9 years ago • 6 comments

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;
    }`

keep-ratio

hmtylmz avatar Apr 30 '16 20:04 hmtylmz

@XamlBrewer Can you let me know where should i change to restrict to only square cropping rectangle?

ArchanaKannantha avatar Nov 14 '16 06:11 ArchanaKannantha

Tomorrow I will create a branch with an almost working version of a fixed-ratio image cropper.

XamlBrewer avatar Nov 14 '16 08:11 XamlBrewer

have you created a sample for fixed ratio?

prashantsrivastava1 avatar May 17 '17 10:05 prashantsrivastava1

Please check this branch: https://github.com/XamlBrewer/UWP-ImageCropper-/tree/fixed-ratio

XamlBrewer avatar May 17 '17 13:05 XamlBrewer

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

prashantsrivastava1 avatar May 17 '17 14:05 prashantsrivastava1

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.

TheSETJ avatar May 23 '17 07:05 TheSETJ