Use of undeclared Identifier 'image' - ios

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:^
{
[self emailImage:image];
}
];
[picker release];
}
I am new to iOS and have just started developing apps. I know Swift language but I have to complete this in Objective C. I am not able to resolve this error.
The link to the images are as follows:

Use this Code,
- (void)imagePickerController:(UIImagePickerController *)photoPicker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType;
mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage ])
{
UIImage * image = (UIImage*) [info objectForKey:UIImagePickerControllerEditedImage];
imageAddView.image = [UIImage squareImageWithImage:image scaledToSize:CGSizeMake(640, 640)];
[photoPicker dismissViewControllerAnimated:YES completion:NULL];
}
}
hope its helpful

your code should be like,
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image=info[UIImagePickerControllerEditedImage];
[self emailImage:image];
[self dismissViewControllerAnimated:YES completion:^
{
//perform anything after dismissing image picker controller
}
];
}
Hope this will help :)

Related

Local address of the photo or image taken with UIImagePickerController

I use the UIImagePickerController to take photo or to select it from an album. Here I put the selected image to the imageView :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.temporaryImageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
But How can i get the address of the selected photo on the device? or the name of it? Is it possible?
May be this can help you;
NSMutableString *imageName = [[[NSMutableString alloc] initWithCapacity:0]];
CFUUIDRef ref = CFUUIDCreate(kCFAllocatorDefault);
if (ref) {
[imageName appendString:NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID))];
}
[imageName appendString:#".png"];
I also recommend you to check this answer;
https://stackoverflow.com/a/16184616/2622013

Image from UIImagePicker to NSMutableArray

Very simply, I want to take a photo using UIImagePicker and place it into an NSMutableArray. I hve the following code below. The camera part works fine and for test purposes the image is displayed in a UIImage called photoImageView. However I can't seem to add the image into the array. Any help gratefully received.
#property (nonatomic, retain) NSMutableArray *photos;
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *photoTaken = (UIImage *)[info valueForKey:UIImagePickerControllerOriginalImage];
photoImageView.image=photoTaken;
[photos addObject:[UIImage photoTaken];
[picker dismissViewControllerAnimated:YES completion:nil];
}
1)Are you initialising the photos NSMutableArray? Sometimes addObject: won't throw an error when trying to insert an object into a NULL NSArray.
2)
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *photoTaken = (UIImage *)[info valueForKey:UIImagePickerControllerOriginalImage];
if (photoTaken)
{
photoImageView.image=photoTaken;
[photos addObject:photoTaken];
}else{
NSLog(#"Selected photo is NULL");
}
[picker dismissViewControllerAnimated:YES completion:nil];
}
Have you instantiated the array somewhere (viewDidLoad for example):
self.photos = [NSMutableArray alloc] init];
?
Modify below after adding to (Ian L )
[photos addObject: photoTaken];
photoTaken is already instantiated as an UIImage object. No need to do :
[photos addObject : [UIImage photoTaken]];
Simply do this :
[photos addObject : photoTaken];

2 UIButtons to set 2 UIImageViews

I've 2 UIButtons, I want both buttons to pick an image, button1 is setting an image to imageview1 and button2 to imageView2. I now created button1 which picks an image and set imageView1 to that image, but if I'm creating button2, I don't now what I have to do in:
- (IBAction)chooseImage1:(id)sender {
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:YES completion:nil];
}
- (IBAction)chooseImage2:(id)sender {
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:YES completion:nil];
}
UIImage *image;
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *mediaURL;
mediaURL = (NSURL *)[info valueForKey:UIImagePickerControllerMediaURL];
image = (UIImage *)[info valueForKey:UIImagePickerControllerOriginalImage];
imageView1.image=image;
[picker dismissViewControllerAnimated:YES completion:nil];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}
Create an index in your .h file. Something like
NSUInteger *selectedImageIndex;
And in your .m file :
- (void)showImagePicker:(UIImagePickerControllerSourceType)source{
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = source;
ipc.allowsEditing = YES;
ipc.delegate = self;
[self presentModalViewController:ipc animated:YES];
}
- (IBAction)chooseImage1:(id)sender {
selectedImageIndex = 1;
[self showImagePicker:UIImagePickerControllerSourceTypePhotoLibrary];
}
- (IBAction)chooseImage2:(id)sender {
selectedImageIndex = 2;
[self showImagePicker:UIImagePickerControllerSourceTypePhotoLibrary];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *img = [info objectForKey:#"UIImagePickerControllerEditedImage"];
if (!img)
img = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
if (selectedImageIndex == 1)
imageView1.image=img;
else
imageView2.image = img;
[picker dismissViewControllerAnimated:YES completion:nil];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}
But then again, this is just one way to do it.

ios pushViewController from imagePickerController: didFinishPickingMediaWithInfo

in my app after i take a photo with the camera i want to navigate to an other viewcontroller in
didFinishPickingMediaWithInfo
Right now, i'm doing it in the dismissViewControllerAnimated function's completition block, but i don't feel like it's the most elegant way to do it. Could you tell me how this could be done better? Here's the exact code
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info[UIImagePickerControllerOriginalImage] scaledCopyOfSize:CGSizeMake(175.0f, 175.0f)];
[self dismissViewControllerAnimated:YES completion:^(void){
setVC = [[SetVCr alloc]init];
[[self navigationController]pushViewController:seVC animated:YES];
}];
}
}
You can push new view controller directly from the picker
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info[UIImagePickerControllerOriginalImage] scaledCopyOfSize:CGSizeMake(175.0f, 175.0f)];
setVC = [[SetVCr alloc]init];
[picker pushViewController:seVC animated:YES];//you can push new view controller directly from the picker
}
}
I suggest setting your completion block to nil and on the next line call the 'performSegueWithIdentifier' method as written below:
[self performSegueWithIdentifier:#"segueToNewcontroller" sender:self];

UIImagepickercontroller Not Selecting Image

I had this working in an old code that I didn’t end up using... now I’m trying it again and it isn’t working. I”m not sure what is wrong. I’d like the user to select an image and then have it available in imageView1 for display. I appreciate the assistance.
- (IBAction)pushPick
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate =self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
//[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage: (UIImage *)image editingInfo:(NSDictionary *)editingInfo {
[picker.parentViewController dismissModalViewControllerAnimated:YES];
imageView1.image = image;
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker.parentViewController dismissModalViewControllerAnimated:YES];
}
Try
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
imageView1.image = image;
[picker release];
[self dismissModalViewControllerAnimated:YES];
}
And make sure the view controller responds to UIImagePickerControllerDelegate.
imagePickerController:didFinishPickingImage:editingInfo: was deprecated in iOS 3.0.
This is how I do this:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
bgImage.image = [info objectForKey:UIImagePickerControllerEditedImage];
UIGraphicsBeginImageContextWithOptions(CGSizeMake(128, 128), YES, 1.0);
[bgImage.image drawInRect:CGRectMake(0,0,128,128)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImageJPEGRepresentation(newImage, 1.0);
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentsFolder = [path objectAtIndex:0];
NSString *tmpPathToFile = [[NSString alloc] initWithString:[NSString stringWithFormat:#"%#/specificImagedName.jpg", documentsFolder]];
if([imageData writeToFile:tmpPathToFile atomically:YES]){
//NSLog(#"write succesful");
}
///////////////////////////////////////////
[po dismissPopoverAnimated:YES];
[picker release];
[tmpPathToFile release];}
it generates a jpg file to the documents folder of your app. Hope it helps..

Resources