Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set dimensions for UIImagePickerController "move and scale" cropbox

How does the "move and scale screen" determine dimensions for its cropbox?

Basically I would like to set a fixed width and height for the "CropRect" and let the user move and scale his image to fit in to that box as desired.

Does anyone know how to do this? (Or if it is even possible with the UIImagePickerController)

Thanks!

like image 756
Thomas K Avatar asked Jan 28 '12 00:01

Thomas K


2 Answers

Not possible with UIImagePickerController unfortunately. The solution I recommend is to disable editing for the image picker and handle it yourself. For instance, I put the image in a scrollable, zoomable image view. On top of the image view is a fixed position "crop guide view" that draws the crop indicator the user sees. Assuming the guide view has properties for the visible rect (the part to keep) and edge widths (the part to discard) you can get the cropping rectangle like so. You can use the UIImage+Resize category to do the actual cropping.

CGRect cropGuide = self.cropGuideView.visibleRect; UIEdgeInsets edges = self.cropGuideView.edgeWidths; CGPoint cropGuideOffset = self.cropScrollView.contentOffset;  CGPoint origin = CGPointMake( cropGuideOffset.x + edges.left, cropGuideOffset.y + edges.top ); CGSize size = cropGuide.size; CGRect crop = { origin, size };  crop.origin.x = crop.origin.x / self.cropScrollView.zoomScale; crop.origin.y = crop.origin.y / self.cropScrollView.zoomScale; crop.size.width = crop.size.width / self.cropScrollView.zoomScale; crop.size.height = crop.size.height / self.cropScrollView.zoomScale;  photo = [photo croppedImage:crop]; 
like image 60
Marc Charbonneau Avatar answered Sep 25 '22 05:09

Marc Charbonneau


Kinda late to the game but I think this may be what you are looking for: https://github.com/gekitz/GKImagePicker

like image 25
Yuriy Avatar answered Sep 23 '22 05:09

Yuriy