UIImagePickerController takePicture - iphone

I want to use UIImagePickerController takePicture method.
the problem his that the UIImagePickerController is not show in the screen and the user cannot press the Use button to accept the img.
Is there is any way to skip this screen and go straight to :
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
for saving the image?

The only way that I have found to do this is to use a custom overlay for UIImagePickerController. You can do that with code akin to that below:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
//create custom overlay and allocate it as "customOverlayView"
picker.cameraOverlayView = customOverlayView;
//do any other setup desired for picker
[self presentViewController:picker animated:YES completion:nil];
[picker release];
Now once the takePicture method is called, the delegate didFinishPickingMediaWithInfo: will be called immediately like you desire.

Related

Passing UIImage to second view controller lags transition

I'm using a UIImagePickerController to select an image from my photo album. Once I've selected the image, I'm passing the image through to a second view controller and displaying it in a UIImageView. See code below:
First view controller:
- (IBAction)selectPhoto
{
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:self.imagePicker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UploadViewController *uploadViewController = [[UploadViewController alloc] initWithNibName:#"UploadViewController" bundle:nil];
[uploadViewController setImage:[info objectForKey:#"UIImagePickerControllerOriginalImage"]];
[picker pushViewController:uploadViewController animated:YES];
}
Second view controller:
- (void)viewDidLoad
{
[super viewDidLoad];
// Set the image view image
imageView.image = self.image;
}
The code does the job, however, when I push from the image picker to my second view controller, it lags as it's transitioning.
Ideally I would like a smooth transition but I would be happy if it just waited half a second or something and then moves smoothly.
Can any explain why this could be happening and how/if I can get around it?
Thanks.
The delay is probably from rendering the image, you could try having your UploadViewController's initial view contain an activity spinner then actually set the image in the viewDidAppear method, this method should be called after the animation is completed.
Try with this , here timer is introduced in order to provide delay(0.5sec) ,
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[NSTimerscheduledTimerWithTimeInterval:0.5 target:self selector:#selector(timerAction:) userInfo:info repeats:NO];
}
-(void)timerAction:(NSTimer *)timer
{
UploadViewController *uploadViewController = [[UploadViewController alloc] initWithNibName:#"UploadViewController" bundle:nil];
[uploadViewController setImage:[[timer userInfo]objectForKey:#"UIImagePickerControllerOriginalImage"]];
[picker pushViewController:uploadViewController animated:YES];
[uploadViewController release];
}

how do I implement "Choose Existing Photo" in my app like in default iphone phonebook?

I want to develop an app which has functionality same as iphone phonebook capturing image and choosing iamge,
what should I to use for doing such
I have made an UIImageView and a button for UIActionSheet,
now I want to perform "Take Photo" and "Choose Existing Photo" options in my app
help me out, I do appreciate
thanks in advance ....
Hey #Veer you need to use UIImagePickerController
check out the documentation
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
and check out this link
http://iphone.zcentric.com/2008/08/28/using-a-uiimagepickercontroller/
It has sample examples about the same.
Edit you can use these methods to get the image in you UIImageView object
- (void)selectPhotos
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
imageView.image = image;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}

using UIImagepickerController cameraoverlayview to take picture?

i am using UIImagepickerController to take pictures from camera..i am using my own view over the camera view by using the cameraoverlayview property...i want to take a picture from camera when user clicks on a button in my custom view...i am using the following code
- (void)viewDidLoad {
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePickerController animated:YES];
imagePickerController.showsCameraControls=NO;
imagePickerController.cameraOverlayView = self.customView;
}
- (IBAction) takePicture
{
[imagePickerController takePicture];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
imageView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissModalViewControllerAnimated:YES];
}
but when i run this code it gives me error
ERROR: FigCreateCGImageFromJPEG returned -12905. Input (null) was 773625 bytes.
and i also get warnings for memory use level 2 and then level 1
and no image is displayed in the imageView.. can anyone help me what i might be doing wrong??
btw i am using iPhone 3G with iOS4.1 installed on it
UIImagePickerControllerOriginalImage is a symbol (an NSString * constant) and you can't assume its value. Use as is, without quotes. Other than that, if you properly retain and create both the picker and the image view, it should work.

Record Video/Take Picture switch in iPhone app?

So i got a iphone app that is a button and when you pressed it i want the camera view to pop up and i want to give the user a choice to take a picture or a video like in the default camera app the one switch thing.
Thanks!
What you are looking for is something called 'UIImagePickerController'
-(void) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
This method is the what would be called when you press your button(s), what i am doing here is I have two buttons, choosePhotoBtn, and takePhotoBtn, the both link to the same method.
If the button that was pressed (the sender) is choosePhotoBtn, then UIImagePickerControllerSourceTypeSavedPhotosAlbum is set as the UIImagePickerController's source type.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
bannerImage.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}
These two methods are delegate methods. They get called when the modelViewController holding the UIImagePickerController is dismissed.
I would recommend this site, as it has a brilliant tutorial on how to use these functions.
http://icodeblog.com/2009/07/28/getting-images-from-the-iphone-photo-library-or-camera-using-uiimagepickercontroller/
This is where i learnt how to use these classes, it seems like the site has had a wordpress comment attack on it at the moment, and firefox is blocking it for me, but if u can get to the page. Its a great resource.

UIImagePicker doesn't showing selected image

I'm new to iPhone and I'm using this code to select an image from the iPhone library and show it in imageView. The library is showing images, but when I'm selecting the image, it doesn't appear in the image view..
- (void)viewDidLoad {
[super viewDidLoad];
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
Please can you tell me what's the problem with the code?
Try with:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *pickedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = pickedImage;
[self dismissModalViewControllerAnimated:YES];
}
UIImagePickerControllerOriginalImage is a string constant that could be different from #"UIImagePickerControllerOriginalImage" string.
Then, it's safe and more clear to former set the image view, and latter to dismiss the modal view controller.
Pay attention that you should invoke dismissModalViewControllerAnimated: on self because you are dismissing the modal view controller "owned" by self.
Bye!
I fixed my issue of "grey box appearing instead of an image in UIImageView".
I forgot to make the Background color of the UIIMageView to be CLEAR COLOR. THe problem was solved by setting background color to clearColor.
Was using XIB and you should also check if anything is laid out wrong in Interface builder in case you are using interface builder to create UI.