ios pushViewController from imagePickerController: didFinishPickingMediaWithInfo - ios

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];

Related

Use of undeclared Identifier 'image'

-(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 :)

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

Send mail with image attachment from camera

There are a LOT of tutorials and info about how to send attachment with your iphone / ipad app, but with pre-defined images or other file-type.
But how do i send an mail with a current file from my iphone/ipad. More specific, an image or image from camera?
Cheers and thank you
If you are using UIImagePickerController to capture image than when you capture image :
#import <MobileCoreServices/UTCoreTypes.h> // framework MobileCoreServices.framework
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self sendMailWithImage:image];
}
[picker dismissModalViewControllerAnimated:NO];
}
- (void)sendMailWithImage:(UIImage *)image
{
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc]init];
mailComposer.mailComposeDelegate = self;
// make sure you can make NSData from the object
[mailComposer addAttachmentData:UIImageJPEGRepresentation(image, 1.0) mimeType:#"image/jpg" fileName:#"what ever you want to call the file"];
[self presentViewController:mailComposer animated:YES completion:nil];
}
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc]init];
mailComposer.mailComposeDelegate = self;
UIImage *myImage = // some code to get your image or what ever file you want
// make sure you can make NSData from the object
[mailComposer addAttachmentData:UIImageJPEGRepresentation(imageToShare, 1.0) mimeType:#"image/jpg" fileName:#"what ever you want to call the file"];
[self presentViewController:mailComposer animated:YES completion:nil];

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];

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