captured image not showing in uiimageView - iphone

I have a uibutton to trigger an iphone's camera to grab an image, and I have a uiimageView in same view to show captured image, but it not showing anything after capturing.
Any solution?

here's my code:
(IBAction)grabImage:(id)sender{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController: picker animated:YES];
[picker release];
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
cameraImageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
}

Related

IOS image capture and save to UIImageView

I am trying to capture an image and save it in the imageview. Below is the code.
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
NSLog(#"Hello");
[picker dismissModalViewControllerAnimated:YES];
[_Image setImage:image];
}
- (IBAction)Capture:(UIButton *)sender {
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController: cameraUI animated: YES completion:nil];
}
The problem is imagepickercontroller is not called at all!! My .h declaration is
#interface AikyaViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
I can get the camera to capture the image, but the image is not saving in my imageview. Infact it is not entering that function itself since its not NSlogging.
Should i have to link anything in the storyboard or any delegates initialisation am i missing?? Plz guide the same.
imagePickerController:didFinishPickingImage:editingInfo: is deprecated
change that method with:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSLog(#"done");
[picker dismissViewControllerAnimated:YES completion:Nil];
[image setImage:[info objectForKey:#"UIImagePickerControllerEditedImage"]];
}
and try to change:
- (IBAction)Capture:(UIButton *)sender {
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
[cameraUI setDelegate:self];
[cameraUI setAllowsEditing:YES];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController: cameraUI animated: YES completion:nil];
}

can't show picking image from photo library

Im using image picker for choose photos from photo library. When i click the button it displays photo library. But when i click particular image it dismiss modalView and image won't load to view.
code:
-(void)showcamera:(id)sender{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc]init];
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePickerController animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
// Dismiss the image selection, hide the picker and
//show the image view with the picked image
[picker dismissModalViewControllerAnimated:YES];
UIImage *newImage = image;
}
Use this code:
in .h file
{
UIImageView *newImage;
UIImagePickerController *imagePicker;
}
in .m file
- (void)imageTaped:(UITapGestureRecognizer *)tapGesture {
imagePicker=[[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.allowsEditing =NO;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
//release picker
[picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
//set image
newImage = [[UIImageView alloc] initWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
[self.view addSubview:mewImage];
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
imgPicked = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
[imagePickerController dismissModalViewControllerAnimated:YES];
}
}
Declare this in .h
UIImage *imgPicked;
in ViewDidLoad
imgPicked = [[UIImage alloc]init];
Best Way is Add Your Image to UIImageView,
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImageView *ImgView = [[UIImageView alloc] initWithFrame:CGRectMake(#"As U Want")];
ImgView.image = image;
[self.View addSubview: ImgView];
[picker dismissModalViewControllerAnimated:YES];
}

Set an image from camera roll to UIImageView

I've implemented a PickerController to have a user select an image, but I want the image the user selects to be displayed on the UIImageView I have.
I use the following to go to the camera roll:
- (void) makeUIImagePickerControllerForCamera:(BOOL)camera {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[picker setMediaTypes:[NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil]];
[self presentModalViewController: picker animated: YES];
[self presentModalViewController: picker animated: YES];
}
Which brings up the camera roll in which a user can click on a photo. However, after the click, it returns to the main view, which is obvious... But how can I assign an action to the button, or image the user selects. Something like UIOKButton?
Something like:
if ([UIImagePickerController presentModalViewController:nil image:nil] == UIOKButton ) {
NSArray *images = [UIImagePickerController images];
for(UIImage* pickerImage in [UIImagePickerController images])
{
myUIImage.image setImage pickerImage;
//^in the view
}
I'm not exactly sure how to go about doing this.
All responses are appreciated.
Thanks!
- (void) makeUIImagePickerControllerForCamera:(BOOL)camera {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[picker setMediaTypes:[NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil]];
[self presentModalViewController: picker animated: YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Dismiss the picker
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
// Get the image from the result
UIImage* image = [info valueForKey:#"UIImagePickerControllerOriginalImage"];
myUIImage.image = image;
}
Use the delegate method: – imagePickerController:didFinishPickingMediaWithInfo:.

multiple UIImageViews with UIImagePickers

I have 3 UIImageViews for which I want to load an image.
For 1 image this is not a problem, but how do I scale to 3?
The code below is what I have right now.
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
[my_image_1 setImage:image forState:UIControlStateNormal];
}
Have you looked at this or this? They seem to be pointing to this resource.
Edit
Based on your comment, I suggest you declare an ivar imageViewToSet in your class and alter your methods in the problem as below,
-(IBAction) getPhoto:(id) sender {
// Add code to identify the sender(button) via tags or outlets and set imageViewToSet to the mapped imageView through a switch or if statement.
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageViewToSet.image = [info objectForKey:UIImagePickerControllerOriginalImage];
}

How to get a copy of the image from UIImagePicker

I've got a very simple app where the user selects a UIImageView and presses a button to take a photo with the camera. The image is then returned and displayed in the UIImageView.
However, since the UIImageViews are sharing the same delegate, when there's already an image in one of the UIImageViews, and I go to take a photo to be placed in another, the previous UIImageView is replaced with empty content (i.e. no image). I guess this is because they're sharing the same delegate. Is there any way I can essentially copy the image instead of referencing the delegate version of it?
Here's some sample code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
[picker.parentViewController dismissModalViewControllerAnimated:YES];
if (topView == YES)
{
NSLog(#"topView = %i", topView);
imageView.image = image;
}
else {
NSLog(#"topView = %i", topView);
imageView2.image = image;
}
}
Thanks!
Edit: Here's the code that gets called by the IBAction on the button presses
- (IBAction) pushPick {
topView = YES;
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (IBAction) pushPick2 {
topView = NO;
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
[picker release];
}
Something like this:
UIImage * newImage = [UIImage imageWithCGImage:[image CGImage]];
use
[image copy];
But remember that you will need to release the object on dealloc