Capture multiple images with camera, after a single 'button press'? - iphone

Basically, through the use of a custom overlay with the camera app, I am wanting multiple images (in my case 5) to be taken, with only one press of a 'capture' button.
I understand that the following code:
- (void)takePicture:(id)sender
{
self.pictureButton.enabled = NO;
[self.delegate takePicture];
}
results in a single image being taken. Is there a way to have this action replicated 5 times, after a single button press? Effectively, this would achieve a 'burst' like effect, as is implemented in the Camera+ app.

Try this code it take 5 pictures from camera and store in an array. use as you need.
int counter;
NSMutableArray * imageArray;
-(void)takePicture
{
counter=0;
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image= [info objectForKey:UIImagePickerControllerEditedImage];
[imageArray addObject:image];
counter++;
if (counter<5)
{
[self dismissModalViewControllerAnimated:NO];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
[self presentModalViewController:imagePicker animated:NO];
[imagePicker release];
}
else
{
[self dismissModalViewControllerAnimated:YES];
}
}

Related

app crashes on image capture

I am capturing images through camera. Then I move to next controller where I display the captured image. I go back to capture image screen and this cycle continues for 10 to 15 times. After this when I try to capture the image the app crashes by giving "low memory warning".
Here is the code:
- (IBAction) takePhoto:(id) sender
{
/*
tempControl *intermediate=[[tempControl alloc] initWithNibName:#"tempControl" bundle:nil];
[self.navigationController pushViewController:intermediate animated:YES];
[intermediate release];
*/
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
imagePickerController= [[UIImagePickerController alloc] init];
[imagePickerController setMediaTypes:[NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil]];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePickerController animated:YES];
}
else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Camera Alert" message:#"Device Lacks Camera" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
alert = nil;
}
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo{
[picker dismissModalViewControllerAnimated:NO];
[picker release];
picker =nil;
/*
cropReciept *recieptToCrop=[[cropReciept alloc] initWithNibName:#"cropReciept" bundle:nil];
[recieptToCrop setReciept:image];
[self.navigationController pushViewController:recieptToCrop animated:YES];
[recieptToCrop release];
*/
OCRDemoViewController *recieptToCrop=[[OCRDemoViewController alloc] initWithNibName:#"CropTestViewController" bundle:nil];
[recieptToCrop setImageToCrop:image];
if ([self.selectedTicketType isEqualToString:#"MAXI QuickPick"]) {
recieptToCrop.selectedValueOfTicket=50;
recieptToCrop.drawNumber=self.selectedDrawNumber;
}
else if ([self.selectedTicketType isEqualToString:#"JUMBO QuickPick"]) {
recieptToCrop.selectedValueOfTicket=36;
recieptToCrop.drawNumber=self.selectedDrawNumber;
}
else if ([self.selectedTicketType isEqualToString:#"MEGA QuickPick"]) {
recieptToCrop.selectedValueOfTicket=24;
recieptToCrop.drawNumber=self.selectedDrawNumber;
}
else if ([self.selectedTicketType isEqualToString:#"REGULAR QuickPick"]) {
recieptToCrop.selectedValueOfTicket=12;
recieptToCrop.drawNumber=self.selectedDrawNumber;
}
else if ([self.selectedTicketType isEqualToString:#"SUPER QuickPick"]) {
recieptToCrop.selectedValueOfTicket=18;
recieptToCrop.drawNumber=self.selectedDrawNumber;
}
[self.navigationController pushViewController:recieptToCrop animated:YES];
[recieptToCrop release];
recieptToCrop=nil;
}
Do not release the picker in the delegate callback, but rather dispatch a block to do it in the next run loop (you can use performSelector after:0 too).
Also use Instruments ObjectAlloc and Leaks to look at what is not getting dealloced.
You need to resize image and then use it.The image clicked from camera is approx. more than 2 mb.Try resizing image captured from camera and then using it.
You need to do:-
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo{
UIGraphicsBeginImageContext(size);//640*920 or what ever you think appropriate
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[picker dismissModalViewControllerAnimated:NO];
[picker release];
picker =nil;
}
And now use finalImage instead of image

UIImagePickerController crash

I'm trying to present an UIImagePickerController. It works fine on simulator, but after few times of presenting, I get an error in the console.
More than maximum 5 filtered album lists trying to register.
This will fail.
Here is the code:
- (IBAction)imageSelectorPressed:(id)sender
{
UIImagePickerController* picker = [[[UIImagePickerController alloc] init] autorelease];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
// Set source to the Photo Library
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
}
picker.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
self.imagePopOverController = popover;
[self.imagePopOverController setDelegate:self];
[self.imagePopOverController presentPopoverFromRect:[kepekBtn frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[popover release];
}
-(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
[popoverController dismissPopoverAnimated:YES];
[self setImagePopOverController:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self.imagePopOverController dismissPopoverAnimated:NO];
[image setImage:[info objectForKey:#"UIImagePickerControllerOriginalImage"]];
picker = nil;
[self setImagePopOverController:nil];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self.imagePopOverController dismissPopoverAnimated:NO];
picker = nil;
[self setImagePopOverController:nil];
}
UPDATE: I've checked the contact app on the iPad. Edited a person, and it has a same error in the console log. BUT it is not crashing, while my app is. So the proper question: How can I fix it?

how to take picture from camera using iphone app

I have implemented picture taking while pressing UI Button butwhen ever i pressed the button got app crashed.
Here is the source code.
.h file
#interface Camera : UIViewController
<UIImagePickerControllerDelegate>
{
UIImagePickerController *mPicture;
}
#property (nonatomic, retain) UIImagePickerController *mPicture;
.m file
#implementaion Camera
#synthesize mPicture;
-(void)pictureButtonPushed
{
UIImagePickerControllerSourceType mType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isSourceTypeAvailable:mType])
{
mPicture.sourceType = mType;
[self presentModalViewController:mPicture animated:YES];
}
}
Thanks in advance
Try this one
Hope it will help :)
-(IBAction)takePhoto
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
}
// image picker needs a delegate,
[imagePickerController setDelegate:self];
// Place image picker on the screen
[self presentModalViewController:imagePickerController animated:YES];
}
-(IBAction)chooseFromLibrary
{
UIImagePickerController *imagePickerController= [[UIImagePickerController alloc]init];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
// image picker needs a delegate so we can respond to its messages
[imagePickerController setDelegate:self];
// Place image picker on the screen
[self presentModalViewController:imagePickerController animated:YES];
}
//delegate methode will be called after picking photo either from camera or library
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissModalViewControllerAnimated:YES];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[myImageView setImage:image]; // "myImageView" name of any UImageView.
}
Here is the code for what you want
- (void)cameraPressed
{
UIActionSheet *menu = [[UIActionSheet alloc]
initWithTitle:#"Set a Prifile Picture"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Choose From Library",#"Take a New Photo",nil];
[menu showInView:[self.navigationController view] ];
}
// actionsheet delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
#try {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.navigationBar.barStyle = UIBarStyleBlack;
imagePickerController.delegate = self;
imagePickerController.allowsEditing = NO;
[appDelegate.objList setHidden:TRUE];
appDelegate.strRefreshCamera = #"notupdate";
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
else {
[appDelegate showAlertWithTitle:#"Info" message:#"This function needs a camera which is only available on the iPhone or iPod."];
}
}
#catch (NSException *e) {
}
}
if (buttonIndex == 0) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.navigationBar.barStyle = UIBarStyleBlack;
imagePickerController.delegate = self;
imagePickerController.allowsEditing = NO;
[appDelegate.objList setHidden:TRUE];
appDelegate.strRefreshCamera = #"notupdate";
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
}
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//flag = TRUE;
[self dismissModalViewControllerAnimated:YES];
//[appDelegate showLoadingView];
UIImage *capturedImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
Use this image object where ever you want to use.

Set an image from camera roll to UIImageView

I've implemented a PickerController to have a user select an image, but I want the image the user selects to be displayed on the UIImageView I have.
I use the following to go to the camera roll:
- (void) makeUIImagePickerControllerForCamera:(BOOL)camera {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[picker setMediaTypes:[NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil]];
[self presentModalViewController: picker animated: YES];
[self presentModalViewController: picker animated: YES];
}
Which brings up the camera roll in which a user can click on a photo. However, after the click, it returns to the main view, which is obvious... But how can I assign an action to the button, or image the user selects. Something like UIOKButton?
Something like:
if ([UIImagePickerController presentModalViewController:nil image:nil] == UIOKButton ) {
NSArray *images = [UIImagePickerController images];
for(UIImage* pickerImage in [UIImagePickerController images])
{
myUIImage.image setImage pickerImage;
//^in the view
}
I'm not exactly sure how to go about doing this.
All responses are appreciated.
Thanks!
- (void) makeUIImagePickerControllerForCamera:(BOOL)camera {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[picker setMediaTypes:[NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil]];
[self presentModalViewController: picker animated: YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Dismiss the picker
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
// Get the image from the result
UIImage* image = [info valueForKey:#"UIImagePickerControllerOriginalImage"];
myUIImage.image = image;
}
Use the delegate method: – imagePickerController:didFinishPickingMediaWithInfo:.

How to get a copy of the image from UIImagePicker

I've got a very simple app where the user selects a UIImageView and presses a button to take a photo with the camera. The image is then returned and displayed in the UIImageView.
However, since the UIImageViews are sharing the same delegate, when there's already an image in one of the UIImageViews, and I go to take a photo to be placed in another, the previous UIImageView is replaced with empty content (i.e. no image). I guess this is because they're sharing the same delegate. Is there any way I can essentially copy the image instead of referencing the delegate version of it?
Here's some sample code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
[picker.parentViewController dismissModalViewControllerAnimated:YES];
if (topView == YES)
{
NSLog(#"topView = %i", topView);
imageView.image = image;
}
else {
NSLog(#"topView = %i", topView);
imageView2.image = image;
}
}
Thanks!
Edit: Here's the code that gets called by the IBAction on the button presses
- (IBAction) pushPick {
topView = YES;
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (IBAction) pushPick2 {
topView = NO;
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
[picker release];
}
Something like this:
UIImage * newImage = [UIImage imageWithCGImage:[image CGImage]];
use
[image copy];
But remember that you will need to release the object on dealloc