Question

I've got some functionality set up. But I'm lost on where to go from here. I can probably figure out what to do with facebook once I know how to actually use the images. I tried saving the image into NSDictionary and then redirecting to a different View Controller, but it won't let me redirect from within the imagePickerController method. So anybody have any idea how to use the image selected from camera roll?

My next idea was to save it in the NSDictionary and then just have a statement checking to see if the NSdictionary value changed but that's not an efficient way of doing it at all.

EDITED below to include the answer provided, but nothing happens, no image displays or anything. What am I missing?

- (void) useCameraRoll
{
if ([UIImagePickerController isSourceTypeAvailable:
     UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
    UIImagePickerController *imagePicker =
    [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType =
    UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.mediaTypes = [NSArray arrayWithObjects:
                              (NSString *) kUTTypeImage,
                              nil];
    imagePicker.allowsEditing = NO;
    [self presentModalViewController:imagePicker animated:YES];
    [imagePicker release];
    newMedia = NO;
}
}

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info
                       objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
    UIImage *image = [info
                      objectForKey:UIImagePickerControllerOriginalImage];


    NSLog(@"image:%@",image);


    displayPhoto.image = image;
    [displayPhoto setFrame:CGRectMake(0, 0, 320, 480)];
    [[self view] addSubview:displayPhoto];

}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
    // Code here to support video if enabled
}
}
Was it helpful?

Solution

Assuming you have called this from a view controller with a button that you have created, why not just add a UIImageView onto your view controller? Call it myPhotoImageView or something like that and then in the didFinishPickingMediaWithInfo method, just add the following line of code after

UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

as

myPhotoImageView.image = image;

To size the image view so that the aspect looks nice do this.

CGSize size = image.size;
CGRect photoFrame;
if (size.width > size.height)
{
    // Landscape
    CGFloat scaleFactor = 320 / size.width;
    photoFrame = CGRectMake(0, 0, 320, size.height*scaleFactor);
}
else
{
    // Portrait
    CGFloat scaleFactor = 320 / size.height;
    photoFrame = CGRectMake(0, 0, size.width*scaleFactor, 320);
}
myPhotoImageView.frame = photoFrame;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top