Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Fabio Floris
526 PointsProblem Capturing Photo and Video Using UIImagePickerController
Hello everyone, I'm finding difficulties with the tutorial SaveImage with parse.com
Following your tutorial, show (excellent) autoresize images when you save on parse.com. The problem I am having is that if you save the photos taken with iphone vertically there are no problems in tableviewcell are displayed perfectly but if you save the photos taken with ipad or landscape format, are seen as if they were badly stretched.
How can I solve this problem?
P.S. Users of the app use this step to insert photos in their profile.
Sorry if the answer is already existing but my English is not very good and probably was not able to find it Thanks to all
Fabio
5 Answers
Stone Preston
42,016 PointsWell the app is only designed for iphone portrait view. But if you wanted to Maybe you could check the initial widths of the captured image compare to the height to see what orientation it was taken in.
if (capturedImage.width > capturedImage.height) {
resizeImage to a size that looks good on the portrait view.
}
else {
resize to the size of the portrait iphone screen
}
The problem is that the app only works in portrait so a picture captured in landscape is going to have to be resized pretty small. and maybe even rotated
Fabio Floris
526 Points: (I'm pretty new on the creation of the App .. Could you give me more precise? For example, where in the code should be inserted resizing this choice? Would not create further damage: (((
Excuse my inexperience
Stone Preston
42,016 Pointswell if you do it incorrectly it could cause some problems yes. The app is designed for portrait view, so photos really wouldnt be taken in landscape view anyways, but if they were you could place the logic I posted above in the method that resizes the picture in the camera view controller. Also note that the code I posted isnt really objective c per se, just psuedo code. so dont paste it in there and expect it to work haha
Fabio Floris
526 PointsSo at the top is part of the measure that optimally resize the photos on iphone homemade horizontal
while in the "else" is part of the classic 320 x480 right? I understand you correctly?
Stone Preston
42,016 Pointsyes. You may have to test a few sizes out for the top part (the if statement) to see which sizes look best
Fabio Floris
526 PointsNothing ... I tried but I could not ... It is probably my inexperience that does not allow me to solve this problem ... Maybe I'm wrong to include it in the code ... or how to set the code ... : (
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
self.FF_ImagePicker = [[UIImagePickerController alloc] init];
self.FF_ImagePicker.delegate = self;
self.FF_ImagePicker.allowsEditing = NO;
self.FF_ImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:self.FF_ImagePicker animated:YES completion:NULL];
}
else if (buttonIndex == 0) {
self.FF_ImagePicker = [[UIImagePickerController alloc] init];
self.FF_ImagePicker.delegate = self;
self.FF_ImagePicker.allowsEditing = NO;
self.FF_ImagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:self.FF_ImagePicker animated:YES completion:NULL];
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
FF_image = [info objectForKey:UIImagePickerControllerOriginalImage];
[FFImageProfile setImage:FF_image];FFImageProfile.contentMode = UIViewContentModeScaleAspectFill;
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Conferma Modifica" message:@"Proviamo questa foto? \n Vediamo come si presenta?" delegate:self cancelButtonTitle:@"Annulla" otherButtonTitles: @"Si! Vediamo", nil];
[alert show];
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (UIImage *)FF_RifimensionaImmagine:(UIImage *)image ToWidth:(float)width andHeight:(float)height {
CGSize DimensioniImmagine = CGSizeMake(width, height);
CGRect DimensioneImageView = CGRectMake(0, 0, width, height);
UIGraphicsBeginImageContext(DimensioniImmagine);
[self.FF_image drawInRect:DimensioneImageView];
UIImage *ImmagineRidimensionata = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return ImmagineRidimensionata;
}
Stone Preston
42,016 Pointslooks like you didnt add any logic in your - (UIImage *)FF_RifimensionaImmagine:(UIImage *)image ToWidth:(float)width method to check for the size dimensions. Within that method is where you would include the if/else
Fabio Floris
526 PointsI had added them but I could not make it work then I reported everything as it was before so you can see what code I'm using for resizing, so maybe you could help me more easily
Fabio Floris
526 PointsPerfect! Thank you very much ... I do the tests and tell you how it was resolved ... I do not close this post because maybe if I have problems paste the code: D! thank you very much!