xamarin ios 裁剪图像 Android

xamarin ios crop image like Android

我正在使用 xamarin iOS。

我想拍张照片,然后让用户可以将图像裁剪成他想要的任何尺寸,如 android:

或者像其他问题一样在画廊中:

iOS - how to implement crop image like default photo album?

我认为这个问题的答案很好,但是我喜欢的所有控件都在 Objective-C 中,我不知道如何将它翻译成 c# for xamarin...

是否存在一些控件(或 iOS 中的内置选项)来调整裁剪大小?

如果您找到了 Obj-C 源来完成您想要的,您可以尝试将 Obj-C 代码移植到 C#。一旦开始,通常不会那么困难。我用 iOS 自定义警报控件做了一次:https://github.com/jsauve/SIAlertView.Xamarin. You could compare the source of those projects to get some ideas on how you'd start porting. Either that, or you could use Objective Sharpie 以帮助您为 Obj-C 库创建 C# 绑定。祝你好运!

float imageWidth = bitmap.Width;
float imageHeight = bitmap.Height;
float width = yourscreenWidth;
float heigth =  yourscreenHeight ;           

var W= width / heigth / (imageWidth / imageHeight);
var W2 = rect.Width() / widt * W;
var H = rect.Height() / heigth;
var cropImageWidth = imageWidth * W2 ;
var cropImageHeight = imageHeight * H ;
var cropImageX = (imageWidth - cropImageWidth) / 2;
var cropImageY = (imageHeight - cropImageHeight) / 2;
Bitmap imageCropped = Bitmap.CreateBitmap(bitmap, (int)cropImageX, (int)cropImageY, 
(int)cropImageWidth, (int)cropImageHeight);