How to force camera to take squared pictures in iOS 7 - iphone

In iOS 7 the camera comes with several modes: video, photo, square and pano. In the application I am developing, we allow users to use the camera to take pictures. We only want squared pictures so we make users crop images afterwards.
Is it possible to programmatically force the camera to only take squared pictures?
This is my code to open the camera:
-(void) openImagePickerSource:(UIImagePickerControllerSourceType)type
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = type;
[self presentViewController:imagePicker animated:YES completion:^{}];
}
I have been looking at the documentation but didn't find anything.

UIImagePickerController has a property called 'allowsEditing'. That will open the Camera in full screen and allows you to resize the taken photo after shot.
imagePicker.allowsEditing = YES;
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
you can get the photo in the protocol method using a key 'UIImagePickerControllerEditedImage'.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *pic = (UIImage *)[info objectForKey:UIImagePickerControllerEditedImage];
}

Related

Received memory warning. with ipad camera

When i open Camera in my app it works fine, but when i navigate in my app and comes back to camera view and again try to open my camera in iPad, app crashes and gives me "Received memory warning". app working fine in iPhone and this issues is only coming in iPad.
My project was without ARC so i converted my project into ARC in the hope to get good results but still my app crashes on camera after little navigation.
can anybody tell me how to decrease memory space with iPad camera so that my apps stop receiving memory warning.
this is my code for camera
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
imagePicker=[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = NO;
//imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:imagePicker animated:YES completion:nil];
}
This is where I get my Image
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[Array removeAllObjects];
[picker dismissViewControllerAnimated:YES completion:nil];
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[array addObject:image];
image=nil;
}
and i have also try to use popOverview for camera but it also didn't work.
In my viewController where I'm calling UIImagePickerController I have used 5 animations, before i was calling animation in viewWillAppear, and app was crashing so i changed Animation calling to ViewDidLoad and camera starting working but only until I navigate to my last view and comes back to open camera again.
I am getting same problem so i do like this.
Set UIImagePickerController as static like this.
static UIImagePickerController *imagePicker;
When you get image in this deleget.
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
#autoreleasepool {// to release memory
// Probelm is you image size.
// When you get this image it is vary large.
// And i hope you are creating multiple copy's of this image.
// when you get image in
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
// In last set image as nil
image = nil;
}
}
Hope this will solve you problem.. :-)
Try to run your app without animation and then try, if it works then you need to improve your animations memory allocation, as animation needs a lot of memory.
Please try below code.try UIImagePickerController with in popover
if([UIImagePickerContrller isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
controller.allowsEditing = YES;
controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
controller.delegate = self;
UIPopoverController *popController = [[UIPopoverController alloc] initWithContentViewController:controller];
popController.popoverContentSize = CGSizeMake(350.0f, 500);
[popController presentPopoverFromRect: self.button.frame inView:self.button.superview
permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]
}

Taking photos using the Iphone camera

We have developed an iPhone app and now wish to utlise the camera to:-
- take a photograph and save it in a specific sub-directory (set up when the App is upgraded/loaded) of Photos but only when the photo is taken from within the app. All other photos should go to the standard photo folder. Is this possible and how can we do it?
- We would like to reference these photos so that pressing a link within the app history accesses that specific photo. Other photos are referenced elsewhere in the app history. Again is this possible and how can we do it?
- (IBAction) buttonname
{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)UIPicker didFinishPickingImage:(UIImage *)info editingInfo:(NSDictionary *)dictionary
{
[UIPicker dismissModalViewControllerAnimated:YES];
imageview.image=info;
}

How to access camera of iPhone using phonegap app

I have a simple application developed for android which takes a photo, accessing the camera of device.
I want the same application to be run on iPhone. For android we write permissions for accessing camera in manifest file. How do you access the camera in iPhone. Where do we need to set up it. Can anyone please help me?
Thanks in advance
Use the Media Capture API in the latest code, or wait for 0.9.6:
http://docs.phonegap.com/phonegap_media_capture_capture.md.html
For accessing the camera in iPhone, you can use following code.
// Camera
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.allowsImageEditing = YES;
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//[self presentModalViewController:imgPicker animated:YES];
[objParent presentModalViewController:imgPicker animated:YES];
[imgPicker release];
Let me know in case of any difficulty.
Below are the delegate method for camera.
Delegate Name: UIImagePickerControllerDelegate, UINavigationControllerDelegate
Methods:
#pragma mark UIImagePickerController delegate
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *imgCapturePhoto = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
[imgPhoto setImage:imgCapturePhoto];
[self dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissModalViewControllerAnimated:YES];
}
Cheers

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.

UIImagePicker not showing Original Image from Photos Library in OS 3.1.2

Holy Crap! Really... I'm frustrated with this problem that get me stuck with my apps for a week now.
Here is the code
- (IBAction)loadTheImage {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
If I set the source as SavedPhotosAlbum (Camera Roll), then it works OK. But when I set it to PhotoLibrary, it just returns nil. And this just happens in OS3.1.2. In OS4 it works OK (ie returns the original image just fine).
Anybody?
A given source may not always be available on every device. This could be because the source is not physically present or because it cannot currently be accessed.
Before attempting to use an UIImagePickerController object to pick an image, you must call [UIImagePickerController isSourceTypeAvailable:] method to ensure that the desired source type is available.