Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take photo with iPhone and then use it!

I have an app that takes a photo and puts it in an image view. Simple. Code looks like this:

- (void)takePhoto:(id)sender
{
    // Lazily allocate image picker controller
    if (!imagePickerController) {
        imagePickerController = [[UIImagePickerController alloc] init];

        // If our device has a camera, we want to take a picture, otherwise, we just pick from
        // photo library
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
        }else
        {
            [imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        }

        // image picker needs a delegate so we can respond to its messages
        [imagePickerController setDelegate:self];
    }
    // Place image picker on the screen
    [self presentModalViewController:imagePickerController animated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    image = [ImageHelpers imageWithImage:image scaledToSize:CGSizeMake(480, 640)];

    [imageView setImage:image];

    [self dismissModalViewControllerAnimated:YES];
}

When I use the Camera Roll everything works great, but if I use the actual Camera the image view is just black. Why is that?

Do I need to save it to the camera roll before I use it in the image view?

like image 659
Linus Avatar asked Apr 29 '11 16:04

Linus


People also ask

Can I make a photo Portrait after taking it iPhone?

Select the photo that you want to change. Tap Edit. Tap Portrait at the top of your screen. Tap Done.

Can a photographer use an iPhone?

Apple offers some of the best cameras to be found on smartphones, especially if you have the latest iPhone Pro or Pro Max. Even professional photographers are using iPhones for some photography work and there's no denying that it's possible to get incredible shots.

How do I turn on live photo?

The Live Photos icon (three circles) is at the top right of the screen. If it doesn't have a line through it, Live Photos is switched on. If the icon has a line through it, tap it to turn on Live Photos. A Live Photo captures 3 seconds of movement and sound.

Why do iPhone pictures look better than Camera?

As a general rule, mobile phones are not able to capture higher-quality images than a DSLR. But many photographers believe their images taken on a mobile phone look better because the phone automatically adds contrast, saturation, skin softening, and background blur.


1 Answers

Ok. Found the solution myself.

I had to dismiss the modal view first...

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

    [self dismissModalViewControllerAnimated:YES]; //Do this first!!
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    image = [ImageHelpers imageWithImage:image scaledToSize:CGSizeMake(480, 640)];

    [imageView setImage:image];  
}
like image 94
Linus Avatar answered Oct 03 '22 06:10

Linus