Image Picker Controller - iphone

I am using the UIImagePickerController to take a picture, that works great, but do not want to use the stand image editor, instead I want to use my own custom image editor. I want to transition to that after I take the picture. I am using the method below to push a view controller after the image picker dismisses.
However, I want to push this before the image picker dismiss to avoid an awkward transition. Any ideas?
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info;

The image picker is already in a navigation interface, so you can push anything you like onto the image picker as a secondary (editing) interface:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage* im = info[UIImagePickerControllerOriginalImage];
if (!im)
return;
SecondViewController* svc =
[[SecondViewController alloc] initWithNibName:nil bundle:nil image:im];
[picker pushViewController:svc animated:YES];
}
You will, however, have to interfere to prevent the image picker from navigating to its own secondary interface. The easy way to do that is to set picker.showsCameraControls = NO and substitute your own controls.
Also, I might be wrong about this, but since you are the navigation controller delegate I think you can just veto an attempt by the image picker to navigate to its own secondary interface. (EDIT: No, I guess not, sorry. The delegate gets a will and a did but not a should message.)

Related

How can I hide the picture preview?

I am new in iPhone development,
I have built new app to take a picture using UIImagePickerController.
Everything is work fine with me, but I need to dismiss the picture preview that appear after I press the capture button.
I search through the net then I found I must use the following routine.
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo
{
[self dismissModalViewControllerAnimated:YES];
}
but it didn't work.
Any help or suggestions, is highly appreciated.
You need to add your own camera overlay view. This view should have a button on to Take a picture.
To add an overlay view, create a view with a background colour of clear, then assign your overlay view to the picker control
self.imagePickerController.showsCameraControls = NO;
self.imagePickerController.cameraOverlayView = myOverlayView;
Then in your overlay view button event you call the following:
[imagePickerController takePicture];
This will then fire the following method on the imagePickerDelegate, and you can save your photo etc in there
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

Access Camera in Same View

When we use UIImagePickerController to get camera action we need to open it in different viewController like as:
UIImagePickerController *imagepicker;
[self presentModalViewController:imagepicker animated:YES];
but I want to use this in same View controller from where this UIImagePickerController is called in different View.
Is it possible?
Try creating a view where you want the image picker to appear say destView.
Create the image picker and then use [destView addSubview: imagepicker.view]
You may need to play with size of destView to get things right.

How to use the picture takes from camera?

Iam developing one application.In that i want to take the picture from camera.For that i used the UIImagePickerControllerSourceTypeCamera.But my problem is how to get that image intomy application.Please tell me how to manage that one.
Thats pretty simple. You have a method in UIImagePickerController which is
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImageWithMediaInfo(NSDictionary *)info. You can get here the image user had selected from UIImagePickerControllerSourceTypeCamera. Now declare an object of UIImage in the header of your AppDelegate. For example I declare UIImage *pickedImage. The purpose to declare this in AppDelegate is that we can use this Image anywhere in our app. Dont retain and synthesize this object. Now come back to your didFinishPickingImage method and now your body of this method should look like this:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)info {
((AppDelegate*)[UIApplication sharedApplication].delegate).pickedImage= [info objectForKey: UIImagePickerControllerOriginalImage];
}
Now you can easily use this image all over your app by just calling ((AppDelegate*)[UIApplication sharedApplication].delegate).pickedImage. Hope it helps.
Happy Coding!

Image editing on iphone

In my app i need to select a image from photos library and then user should be able to crop or scale the the image. Can any one please help me?
UIImagePickerController should do the trick.
UIImagePickerController *picker = [UIImagePickerController new];
picker.delegate = self;
picker.allowsEditing = YES;
[yourViewController presentModalViewController:picker];
Then we need to implement the delegate method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
}
You can use a UIImagePickerController to let the user select an image from the photos library.
#denizen
The
[yourViewController presentModalViewController:picker]; needs an animated:BOOL.
Like: [yourViewController presentModalViewController:picker animated:YES];
You can also have a look at SSPhotoCropperViewController. It’s a custom view controller that provides a simple, configurable and easy-to-use UI for cropping and scaling photos in iPhone & iPod Touch apps.
For picking photos from the Photo Library, UIImagePickerController does well. However you cannot use it for the photos you get from another sources, say Flickr, FB etc.
Here is the tutorial and the source code on GitHub for SSPhotoCropperViewController.

iPhone camera can't open from landscape application

I am creating a landscape only application using sdk 3.0 that uses mapkit. I need to use iphone camera in my application. But I am getting following warning when I try to open camera.
"Can't perform full-screen transition. The fromViewController's view must be within a view that occupies the full screen."
The view from which I am calling camera method is mapview with size of 480*320. I have written following code to call camera:
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController: picker animated:YES];
[picker release];
After that I have written the usual method :
-(void)imagePickerController : (UIImagePickerController *)picker didFinishPickingImage : (UIImage *)image editingInfo : (NSDictionary *)editingInfo
But this is never called , since camera is never opened. So my question is what am I missing here...? I am testing this app on actual iphone device , not on simulator. I have used this code in another app and it works fine. But here, it simply doesnt work! Plz help if you have any idea about this..
it sounds like the warning is telling you the problem: the parent view you're passing in to presentModalViewController needs to be a full-screen view. So instead of using "self" in this code you need to use something else, like the parent view controller.
now, you're going to have another problem, because the camera controller doesn't like landscape mode, so you may have to switch back to portrait mode before showing it....
just replace "self" with the parent ViewController which is probably declared in you appDelegate.