0

I'm using xamarin iOS.

I want to take a photo, and afterwards make the posibility for the user to crop the image to any size he wants, like in android:

https://i.stack.imgur.com/TXapR.png

or in the galery like this other question:

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

I think the answer for that question is pretty good, but all the controlls that I have fond are in Objective-C, and I don't know how to translate it to c# for xamarin...

Does exists some control (or built in option in iOS) to make the crop resizable?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Albert Cortada
  • 737
  • 3
  • 10
  • 25

2 Answers2

1

If you've found Obj-C source to accomplish what you want, you can try porting the Obj-C code to C#. It's usually not that tough once you get started. I did it once with an iOS custom alert control: 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 to help you create C# bindings for the Obj-C library. Good luck!

NovaJoe
  • 4,595
  • 6
  • 29
  • 43
0
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);
auslander
  • 470
  • 5
  • 17