Capturing image using custom buttons in cameraoverlayview in iphone - iphone

Thanks in advance.
I have created a custom toolbar on cameraOverlayView. One of the toolbar buttons will trigger the takeSnap method –
-(IBAction)takeSnap
{
NSLog(#"take snap called");
[self.picker takePicture];
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editingInfo
{
UIImage *image = img;
NSLog(#"image : %#",image);
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
NSLog(#"Did cancel called");
}
But it is not calling the delegate methods after capturing. The view continues to remain in capture mode. If any one know the reason please help me.

Its very likely that you haven't assigned a delegate properly.

Related

ios custom takePicture button

I want my custom button to take a picture using UIImagePickerController and to save it in my device.
I can save the picture in the device using the default camera controls, although when i turn them off and start using my custom button it doesn't do the job.
- (IBAction)takePhoto:(id)sender {
[picker takePicture];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
UIImageWriteToSavedPhotosAlbum(chosenImage, nil, nil, nil);
[picker dismissViewControllerAnimated:YES completion:nil];
}
didFinishPickingMediaWithInfo is being called but the picture isn't being saved.
How can i achieve this?
I did something similar and used this tutorial to get be started. Have a look.
http://www.musicalgeometry.com/?p=821

how to identify the image take from uiimagePicketController is screenshot or camera image?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editInfo {
NSLog(#"done");
headingLabel.hidden= NO;
//[self playMovie];
[picker dismissViewControllerAnimated:YES completion:nil];
[self setupCroppingTool:selectedImage];
}
this is the code,so how can i identify the selectedImage is screenshot or camera image
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editInfo
This method picks the image from photo library. You cant compare a screenshot image with a normal image because both are UIImage.
May be help..
I think source property of UIImagePickerController help you.
Example.
UIImagePickerController *abc = [[UIImagePickerController alloc] init];;
abc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
You can use one of this..
UIImagePickerControllerSourceTypePhotoLibrary
UIImagePickerControllerSourceTypeCamera
UIImagePickerControllerSourceTypeSavedPhotosAlbum
Look at the image metadata - date, keywords, geolocation... and compare that.

how to call imagepickerdelegate method two times when picking images from dirrerent button

I'm relatively new to X Code
and
I m working on photo collage App , when i pick image from one picker then image picker is working properly but i want to pick different images from different imagepicker then image picker is not working properly
Anyone help me solve my problem. Here is my code
`
-(IBAction)imagepickMethod1:(id)sender
{
imagepicker=[[UIImagePickerController alloc]init];
imagepicker.delegate=self;
imagepicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagepicker animated:YES];
button1.tag=100;
}
-(IBAction)imagepickMethod2:(id)sender
{
imagepicker1=[[UIImagePickerController alloc]init];
imagepicker1.delegate=self;
imagepicker1.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagepicker1 animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:YES];
imagepicker.view.hidden=YES;
photoPreviewImageView.image=image;
}
-(void)imagePickerController1:(UIImagePickerController *)picker1 didFinishPickingImage:(UIImage *)image1 editingInfo:(NSDictionary *)editingInfo1
{
[picker1 dismissModalViewControllerAnimated:YES];
imagepicker.view.hidden=YES;
photoPreviewImageView1.image=image1;
}
`
//Take two imageView in your .h file
UIImageView *imgViewForFirstPicker;
UIImageView *imgViewForSecondPicker;
// Alloc these images in view did load
imgViewForFirstPicker = [[UIImaeView allo] initWithFrame:(give your rect)];
// Similarly for second imageView and add to both in self.view
-(IBAction)imagepickMethod1:(id)sender
{
UIImagePickerController *imagepicker=[[UIImagePickerController alloc]init];
imagepicker.delegate=self;
imagepicker.tag=100;
imagepicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagepicker animated:YES];
}
-(IBAction)imagepickMethod2:(id)sender
{
UIImagePickerController *imagepicker1=[[UIImagePickerController alloc]init];
imagepicker1.delegate=self;
imagepicker1.tag=101;
imagepicker1.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagepicker1 animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage: (UIImage*)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:YES];
if(picker.tag == 100)
imgViewForFirstPicker.image=image;
else
imgViewForSecondPicker.image=image;
}
try this one hope it will help you
UIImagePickerController creates a pretty heavy object, So I don't think it is advisable to create multiple instances of it. May be this is what is causing the problem if you are doing the same.. It would be nice if you could share your code as well so we can have more insights into your problem
It is advisable to just use on image picker. From the code you provided you are trying to create two different imagepicker delegate methods, but in reality only one of them will be called both times.
You should create on instance of imagePicker and change its tag depending on which image you needed changed and then in the -didFinishPickingImage check if (picker.tag == SOME_TAG) then set appropriately.

Going to a different view once photo selected from camera/library

I am writing an app that has an initial view containing 2 buttons - one that allows the user to take a photo with the camera and the other that allows him to select a picture from the library.
I've written the code that allows that to happen, but after selecting the picture, I want to go to another view that allows, say, sharing the picture or whatever. Could anyone tell me how to do something like "whenPhotoIsSelected, view = newView"?
This is my code so far:
#pragma mark -
-(IBAction) getCameraPicture: (id) sender{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = (sender == takePictureButton) ?
UIImagePickerControllerSourceTypeCamera :
UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
[picker release];
}
I am aware of the existence of
-(void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
but how exactly do I use it? I tried it and it crashes...
Implement the UIImagePickerControllerDelegate in your ViewController.
To do that add <UIImagePickerControllerDelegate> to your ViewController's interface declaration (in the .h file) like so:
#interface YourViewController : UIViewController <UIImagePickerControllerDelegate> {
// instance variable declarations etc.
}
Then in your ViewController's .m file you actually implement the method -(void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo instead of calling it, like so:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
// add the new view, for example you could push it on your navigation stack if you use a UINavigationController
}
That method will be called by the UIImagePicker when an image was selected.

how to know image picking in uiimagepicker?

how to know image picking in uiimagepicker and how to modify the picking image or how to call after image picking? and how to get the picking image as background image for next view using xcode for iphone?
You can refer UIImagePickercontroller and use the UIImagePickerController's delegate methods UIImagePickerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Get the image picked by the image picker
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
//Do something
}
Use the UIImagePickerController's delegate methods:
- (void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info {
// Get the image picked by the image picker
UIImage *image :[info objectForKey:#"UIImagePickerControllerOriginalImage"] ;
//Do something
[picker dismissModalViewControllerAnimated:YES];
}
Or I am sure this link may be helpful to you:
http://www.icodeblog.com/2009/07/28/getting-images-from-the-iphone-photo-library-or-camera-using-uiimagepickercontroller/