Trouble updating a UIImageView selected from iphone photo library - ios

I'm using the code below to retrieve an image from the iphone photo library. self.selectedImageView.image is an image view located on top of the view of the current view controller. Everything in xcode seems linked correctly; the image view is wired and so fourth.
Problem:
After selecting an image I can see that this method is called but the new image does not update. The image view is completely blank.
Question: Is their some sort of refreshing that needs to take place after reassigning a new image to an image view?
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(#"image selected");
[picker dismissViewControllerAnimated:YES completion:NULL];
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.selectedImageView.image = chosenImage;
}

Try using the key UIImagePickerControllerOriginalImage instead. The key your currently using, UIImagePickerControllerEditedImage, is for accessing images that the user has edited.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
// Get the image first then dismiss the controller.
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:nil];
self.selectedImageView.image = chosenImage;
}

may this help you and above posted code by Gyanendra singh also correct even you can follow his code also.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//here we are storing the image in uiimage after selecting from library
UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
//set image to image view
[imageView setImage:image];
//after selecting photo from library dismiss photo library
[self dismissModalViewControllerAnimated:YES];
}

Related

How to set up a view for preview the image after you selected it in UIImagePickerController?

I would like to create a view to preview the image after you selected one in the UIImagePickerController. I have tried to create a view controller and push the picker controller to another view controller.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
ImagePreviewController *ipc = [self.storyboard instantiateViewControllerWithIdentifier:#"ImagePreviewController"];
UIImage * image = [info valueForKey:UIImagePickerControllerOriginalImage];
ipc.selectedImage = image;
[picker pushViewController:ipc animated:YES];
}
As you can see I have tried to push the UIImagePickerController to another view and tries to preview it. But unfortunately the ipc object shows null when I debug it. I understands that the UIImagePickerController is inherited from the UINavigationController. Is it because in this navigation controller it can't find the view of my ipc? If yes, how can I add it into the UIImagePickerController so it can push to the preview image view? If not, how can I set up a preview image view properly?
Update: If I put
ImagePreviewController *ipc = [ImagePreviewController alloc]init];
instead, when it pushes, it's a black screen.
You should dismiss the image picker and then present your custom UIViewController subclass
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIViewController *presentingViewController = picker.presentingViewController;
ImagePreviewController *ipc = [self.storyboard instantiateViewControllerWithIdentifier:#"ImagePreviewController"];
UIImage * image = [info valueForKey:UIImagePickerControllerOriginalImage];
ipc.selectedImage = image;
[presentingViewController dismissViewControllerAnimated:YES completion:^(BOOL animated){
[presentingViewController presentViewController:ipc animated:YES completion:nil];
}];
}

how to slide library image in image view

i am new programming how ever i developing and application i wan`t to access all library image in my image view and slide the image and see it . like and any camera we see all images can any body suggest!
how to implement all library image in my view and slide it i am implementing this but through that i can access only single image.
picker = [[UIImagePickerController alloc]init];
picker.delegate=self;
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:picker animated:YES completion:NULL];
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
image=[info objectForKey:#"UIImagePickerControllerOriginalImage"];
[_imageview setImage:image];
[self dismissViewControllerAnimated:YES completion:NULL];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:NULL];
}
In oder to get all photo / assets from the native photo application you can use the Photos Framework. You can find the detailed documentation from this link
https://developer.apple.com/library/ios/documentation/Photos/Reference/Photos_Framework/index.html#//apple_ref/doc/uid/TP40014408

Loading my image on new screen

I have everything i want working up to the view you can see in the picture, i don't want the image to load on the same screen, how can i get it to load in a new screen. i have tried a few tutorials, i have had no luck as yet
The image that has been loaded from the gallery is the brick wall in the background.
the reason i want to load it in a new screen is so i can put a new toolbar that will allow me to drag images and overlay them on top of the image selected from taller or taken with the camera
Thanks in advance and sorry for asking about something that sounds so simple, I'm just very new to all this.
http://imageshack.com/a/img845/4808/9lz8.png
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
How do i open new screen when didFinishPickingMediaWithInfo
If you need to see me more code please let me know which, I'm not sure what code you need to see :) thank you for your reply.
If you want the image to load on a new screen, you'll need to create a second viewController, and add an imageView to that viewController.
then in your didFinishPicking method, instead of setting the image to the imageView of the current ViewController, instantiate a new imageController, set the imageView property of the new viewController, and then push your new viewController onto the navigation stack if you're using a navigation controller. If you're not using a navigation controller, you could just push the second view controller modally.
So in your didFinishPicking method it would be
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
NewViewController *newViewController = [[NewViewController alloc] init];
newViewController.imageView.image = chosenImage; //or whatever the imageView property is called of your new view controller
[self presentViewController:newViewController animated:YES completion:nil];
(I haven't tested this code - it's off the top of my head so reader caution advised and this is the modal method)
Let's try:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:^{
// I think you should not call `presentViewController` newViewController at this screen because it maybe be destroyed
// So, call newViewController at parentClass by delegate of block
// and assign new image to the screen which need to show
}];
}

How do I reference the picture I just took in iOS?

I'm writing an app that allows the user to take a picture and then shows it in an image view.
I get that I need to write a line of code similar to the following: _imageView.image = picker.image;, but I'm not sure what I need to substitute for picker.image. That is what I currently have and it gives me an error.
Basically, what I'm asking is how do I reference the picture that was just taken? Where does this picture go (in memory?) after you take it? How can I reference it later (like for displaying and saving and that sort of stuff)?
I've already read the official Apple documentation and looked at a few tutorials and the answer doesn't seem to be in any of them. As I've mentioned in previous posts, I tend to have a lot of trouble parsing the Apple documentation, so it's been mostly useless for me.
Thank you!
I use the following delegate method to get whatever picture a user picked from the photo picker view
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:false completion:nil];
image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
call the cameraTapped method on tapping your camera button
-(IBAction)cameraTapped:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
else
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePickerController setDelegate:self];
[self presentViewController:imagePickerController animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// photo
_imageView.image = info[UIImagePickerControllerOriginalImage]];
[self dismissViewControllerAnimated:YES completion:nil];
}

Do you have any methods for going from CameraRoll to a new view controller?

I'm trying to go from Camera Roll to a new view controller. So basically I want to be able to choose a picture and after choosing the picture, it will be displayed on an imageView on a new view controller? Is that hard to make ?
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:
(NSDictionary *)info{
self.chosenImage = info[UIImagePickerControllerOriginalImage];
[self.imageView setImage:self.chosenImage];
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:nil];
}
in your image picker delegate methods, whenever you take image it goes in following method
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
//store image here as NSData or as you like
// go to the view controller when you want to use image and use the image data
// do all the stuf you need in this method
}

Resources