private void UpdateImageSize() { double width = croppedImage.Width; double height = croppedImage.Height; var isize = croppedImage.ImageSize; double iwidth = isize.Width; double iheight = isize.Height; if (iheight <= 0) { return; } if (height <= 0) { Device.BeginInvokeOnMainThread(async() => { await Task.Delay(500); UpdateImageSize(); }); } if (Scaled) { //zoomView.MinimumScale = scale; //Debug.WriteLine($"Exit New Scale: {scale}, diff: {diff}"); return; } Scaled = true; this.IsClippedToBounds = true; var ciAspect = width / height; var imageAspect = iwidth / iheight; double scale = 1.0; double pad = 0; if (ciAspect > imageAspect) { scale = ciAspect / imageAspect;// width / (imageAspect * height) ;// ciAspect/imageAspect ;// width /(imageAspect/height); pad = (width - imageAspect * height) / 2; zoomView.CropPadding = new Thickness(pad, 0, pad, 0); // set top/bottom padding... } else { scale = height / (width / imageAspect);// height*imageAspect/width ;// height/(width/imageAspect); pad = (height - width / imageAspect) / 2; // set left/right padding... zoomView.CropPadding = new Thickness(0, pad, 0, pad); } var diff = Math.Abs(zoomView.Content.Scale - scale); //Debug.WriteLine($"New Scale: {scale}, diff: {diff}"); croppedImage.AnchorX = 0.5; croppedImage.AnchorX = 0.5; croppedImage.TranslationX = 0; croppedImage.TranslationY = 0; croppedImage.Scale = scale; //croppedImage.AnchorX = 0; //croppedImage.AnchorX = 0; zoomView.MinimumScale = scale; zoomView.OnPanUpdated(zoomView, new PanUpdatedEventArgs(GestureStatus.Started, 0, 0, 0)); zoomView.OnPanUpdated(zoomView, new PanUpdatedEventArgs(GestureStatus.Running, 0, 0, 0)); zoomView.OnPanUpdated(zoomView, new PanUpdatedEventArgs(GestureStatus.Completed, 0, 0, 0)); UpdateCropSize(); zoomView.Refresh(); }
private void EndPan(AtomZoomView element, float x, float y) { element.OnPanUpdated(this, new PanUpdatedEventArgs(GestureStatus.Completed, 0, x, y)); _panStarted = false; }