picture taken with camera doesn't resize in uiimageview

DevilInDisguise

My code

- (IBAction)takePhoto:(UIButton *)sender {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
    UIImagePickerController *picker = [UIImagePickerController new];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:picker animated:YES completion:nil];
}else{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR!" message:@"Device has no camera!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}
}

and the delegate

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.userImage.image = chosenImage;

[picker dismissViewControllerAnimated:YES completion:NULL];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

[picker dismissViewControllerAnimated:YES completion:NULL];

}

Well, thats pretty simple and basic. My problem is that after assigning my image to the UIImageView I have (which has a pinned/fixed width and height) instead of resizing itself to the size of the uiimageview it stretches throughout my whole view, working more as a background that an image placed where it should be. Again, the width and height of my uiimageview has been pinned. Can anybody help? thanks

Cyrille

The contentMode of your UIImageView should be UIViewContentModeScaleAspectFit, instead of UIViewContentModeCenter as it seems to be.

If you need to change the content mode on the fly, just add this line:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    self.userImage.image = chosenImage;

    // Add this line
    self.userImage.contentMode = UIViewContentModeScaleAspectFit;

    [picker dismissViewControllerAnimated:YES completion:NULL];
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get uri of picture taken by camera

From Dev

Delete picture taken from camera

From Dev

Div/Picture doesn't resize properly on zoom

From Dev

Images not being saved when picture is taken by camera app that isn't the stock camera

From Dev

Xamarin Forms - Resize Camera Picture

From Dev

Android adding image to picture taken with camera

From Dev

Upload a picture taken by the camera to a server with limited size

From Dev

Getting the URL of picture taken by camera with Photos Framework

From Dev

Strange size of picture taken with Android Camera

From Dev

UIImageView won't resize properly

From Dev

UIImageView won't resize with image

From Dev

Android Camera Preview Stretched in Preview, Not After Picture Taken

From Dev

Trying to display the picture in my app that was just taken with the built in camera app

From Dev

UIImagePickerController shows last picture taken instead of camera input

From Dev

How to set the size and quality of a picture taken with the android camera?

From Dev

Custom camera shows dark picture preview when photo taken on Nexus

From Dev

Android Camera: Get Picture Uri after the photo is taken

From Dev

Is there a way to specify the file name in advance for the picture taken with the flutter camera plugin?

From Dev

How to show Picture into a activity after taken and saved from custom camera

From Dev

Decode datamatrix out of picture taken by camera2 with zxing

From Dev

Camera2 API picture taken wont show at gallery apps

From Dev

Picture taken with camera as div background image Ionic 3

From Dev

Resize image taken from gallery or camera, before being uploaded

From Dev

Why are Fullscreen Photos taken by Camera on iphone not displayed in UIImageview when allowsEditing is disabled?

From Dev

Masking a UIImageView doesn't work

From Dev

Camera Orientation Change When Picture Taken. Even When Orientation is locked.

From Dev

Android: Can't get the size of photo taken by camera acitivity

From Dev

Android Camera2 : can't take picture with front camera

From Dev

<p:sticky> doesn't resize on window resize

Related Related

  1. 1

    Get uri of picture taken by camera

  2. 2

    Delete picture taken from camera

  3. 3

    Div/Picture doesn't resize properly on zoom

  4. 4

    Images not being saved when picture is taken by camera app that isn't the stock camera

  5. 5

    Xamarin Forms - Resize Camera Picture

  6. 6

    Android adding image to picture taken with camera

  7. 7

    Upload a picture taken by the camera to a server with limited size

  8. 8

    Getting the URL of picture taken by camera with Photos Framework

  9. 9

    Strange size of picture taken with Android Camera

  10. 10

    UIImageView won't resize properly

  11. 11

    UIImageView won't resize with image

  12. 12

    Android Camera Preview Stretched in Preview, Not After Picture Taken

  13. 13

    Trying to display the picture in my app that was just taken with the built in camera app

  14. 14

    UIImagePickerController shows last picture taken instead of camera input

  15. 15

    How to set the size and quality of a picture taken with the android camera?

  16. 16

    Custom camera shows dark picture preview when photo taken on Nexus

  17. 17

    Android Camera: Get Picture Uri after the photo is taken

  18. 18

    Is there a way to specify the file name in advance for the picture taken with the flutter camera plugin?

  19. 19

    How to show Picture into a activity after taken and saved from custom camera

  20. 20

    Decode datamatrix out of picture taken by camera2 with zxing

  21. 21

    Camera2 API picture taken wont show at gallery apps

  22. 22

    Picture taken with camera as div background image Ionic 3

  23. 23

    Resize image taken from gallery or camera, before being uploaded

  24. 24

    Why are Fullscreen Photos taken by Camera on iphone not displayed in UIImageview when allowsEditing is disabled?

  25. 25

    Masking a UIImageView doesn't work

  26. 26

    Camera Orientation Change When Picture Taken. Even When Orientation is locked.

  27. 27

    Android: Can't get the size of photo taken by camera acitivity

  28. 28

    Android Camera2 : can't take picture with front camera

  29. 29

    <p:sticky> doesn't resize on window resize

HotTag

Archive