ios custom takePicture button - iphone

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

Related

UIImagePicker always issues imagePickerControllerDidCancel in iOS 5

So I'm retesting one of my apps that I know works with iOS 4.2 and up on the new iOS 5, and for some reason, they don't want to play nice. My UIImagePicker delegate will, upon the user selecting a photo from the photo library, ALWAYS issue an imagePickerControllerDidCancel, and never allow the picture to be selected (just says the image is nil when I try to load it). This is the code I know works on previous versions of iOS, so I have no idea why it wouldn't work now, unless Apple has changed how UIImagePicker works.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage : (UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
mainPhoto.image = image;
[self saveImage:image];
[picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissModalViewControllerAnimated:YES];
}
And here is the code that calls the UIImagePicker:
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
[picker release];
Any ideas? Or has anyone else had this problem?
Documentation for
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage : (UIImage *)image editingInfo:(NSDictionary *)editingInfo says,
"Deprecated in iOS 3.0. Use imagePickerController:didFinishPickingMediaWithInfo: instead.".Try to follow the suggestion and let us know if you still face issue ?

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/

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.

UIImagePickerController continue to select image

I know UIImagePickerController can only select one image from library each time. When user select one image, UIPickerController will disappear. But I noticed the app "Good Reader", when it launchs UIImagePickerController, after user choose one image, it prompt a small window says "processing the image", but UIImagePickerController does not dissappear which will let the user continue to choose other images.
I do not know how this can be realized?
Welcome any comment.
Thanks interdev
I would think that you just dont call [self dismissModalViewControllerAnimated:YES]; until you are doing processing.
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
// do your magic here, and display processing UI
[self dismissModalViewControllerAnimated:YES];
[picker release];
}

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.