KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am using the UIImagePickerController to select images for my app. However I am facing some challenges with regards to maintaining aspect ratio of the selected images For example, I have a raw image on the phone as follows (not square image): After selecting the image on iphone via the 'move and scale' page to crop image, the result is as follows: (aspect ratio is still maintained here) My app will display the selected image in a UIImageView with a square frame (200 x 200). After setting the selected image to the UIImageView (UIImageView.image = selectedImage), the image's aspect ratio is not maintained but instead followed the frame of the UIImageView: (The image looks skewed now in my UIImageView): Is there any way to maintain the aspect ratio of the image in this case? EDIT: Update expected result After some thinking, I realize that the best way to resolve my issue is to ensure that for such images (non square), I need to 'convert' them into square images i.e. fill the empty spaces on top and bottom of images to make a square e.g. Expected image: (with the top and bottom borders added) EDIT: Update with sample code - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo { self.imageView.contentMode = UIViewContentModeScaleAspectFill; self.imageView.image = image; [[picker parentViewController] dismissModalViewControllerAnimated:YES]; //Compress image UIImage *image = [self scaleImage:img toSize:CGSizeMake(612.0,612.0)]; se
Tags (comma-separated)
Save Edits
Cancel