public async void OKImageEditing(object sender, EventArgs e) { //c.CW("OKImageEditing xDist " + xDist + " yDist " + yDist + " intrW " + intrinsicWidth + " intrH " + intrinsicHeight + " scaleFactor " + scaleFactor + " img left " + ImageEditor.Frame.Left + " frame left " + ImageEditorFrameBorder.Frame.Left + " img top " + ImageEditor.Frame.Top + " frame top " + ImageEditorFrameBorder.Frame.Top); //for device rotation, otherwise retains the set float values xDist = ImageEditor.Center.X - ImageEditorFrameBorder.Center.X; yDist = ImageEditor.Center.Y - ImageEditorFrameBorder.Center.Y; //c.CW("OKImageEditing new xDist " + xDist + " yDist " + yDist); if (IsOutOfFrameX(xDist) || IsOutOfFrameY(yDist)) { c.Alert(LangEnglish.ImageEditorAlert); return; } nfloat w = ImageEditor.Image.Size.Width; nfloat h = ImageEditor.Image.Size.Height; nfloat x = ((intrinsicWidth * scaleFactor - ImageEditorFrameBorder.Frame.Width) / 2 - xDist) * w / (intrinsicWidth * scaleFactor); nfloat y = ((intrinsicHeight * scaleFactor - ImageEditorFrameBorder.Frame.Height) / 2 - yDist) * h / (intrinsicHeight * scaleFactor); nfloat cropW = ImageEditorFrameBorder.Frame.Width * w / (intrinsicWidth * scaleFactor); nfloat cropH = cropW; //c.CW("OKImageEditing borderW " + ImageEditorFrameBorder.Frame.Width + " imageDisplayW " + ImageEditor.Frame.Width + " imgW " + w + " imgH " + h + " startX " + x + " startY " + y + " W " + cropW + " H " + cropH); /* * iPhone 11 Pro display issues in landscape * * * Pink flowers * Right edge is 3 px to right in 3x zoom * * OKImageEditing xDist -430.5 yDist 287 intrW 382.666666666667 intrH 287 scaleFactor 3 img left -598.333333333333 frame left 262.666666666667 img top 68 frame top 68 * IsOutOfFrameX 574 574 * IsOutOfFrameY 430.5 430.5 * OKImageEditing borderW 287 imageDisplayW 1148 imgW 4032 imgH 3024 startX 3024 startY 0 W 1008 H 1008 * * img w 1148 dp * frame right: 549,666 dp 1649 px * img right = frame right, actual 1652 px * * * Pink flowers * Right edge 1 px to right in 1x zoom * * OKImageEditing xDist -47.8333333333333 yDist 0 intrW 382.666666666667 intrH 287 scaleFactor 1 img left 167 frame left 262.666666666667 img top 68 frame top 68 * IsOutOfFrameX 191.333333333333 191.333333333333 * IsOutOfFrameY 143.5 143.5 * OKImageEditing borderW 287 imageDisplayW 382.666666666667 imgW 4032 imgH 3024 startX 1008 startY 0 W 3024 H 3024 * * img w 382.666 * img right 549.666 dp 1649 px actual 1650 px * * * Cactus flower / tree leaves * Right edge is -1 px to left in 3x zoom * * OKImageEditing xDist -504.668539325843 yDist 287 intrW 432.112359550562 intrH 287 scaleFactor 3 img left -746.501872659176 frame left 262.666666666667 img top 68 frame top 68 * IsOutOfFrameX 648.168539325843 648.168539325843 * IsOutOfFrameY 430.5 430.5 * OKImageEditing borderW 287 imageDisplayW 1296 imgW 4288 imgH 2848 startX 3338.66666666667 startY 0 W 949.333333333333 H 949.333333333333 * * img w 1296.337077 dp * img right 549.835205 dp 1649,505615 px actual 1648 px */ UIImage im = CropImage(ImageEditor.Image, (int)Math.Round(x), (int)Math.Round(y), (int)Math.Round(cropW), (int)Math.Round(cropH)); c.Log("Cropped width " + im.Size.Width + " height " + im.Size.Height); var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string cacheDir = Path.Combine(documents, "..", "Library/Caches"); string fileName = Path.Combine(cacheDir, selectedImageName); string ext = selectedImageName.Substring(selectedImageName.LastIndexOf(".") + 1).ToLower(); NSData data; if (ext == "jpg" || ext == "jpeg") { data = im.AsJPEG(); //default compression quality is 1. File size example: 0.99: 1710751, 1: 3502822 } else { data = im.AsPNG(); } if (!data.Save(fileName, false, out NSError error)) { c.ReportError("Error while cropping image: " + error.LocalizedDescription); } else { ImageEditorControls.Hidden = true; TopSeparator.Hidden = true; ImageEditorStatus.Hidden = true; ImageEditor.Hidden = true; ImageEditorFrame.Hidden = true; ImageEditorFrameBorder.Hidden = true; ImageEditor.Image = null; await UploadFile(fileName, RegisterActivity.regsessionid); //works for profile edit too } }