When I present a UIImagePickerController in my iPhone App, it always comes up with a white square with a frame around it, and the user has can zoom in and out of an image and make it fit within the white square. Whatever they fit in the white square is what is returned to:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)info
and it is always 640x640.
Why can't the user select an entire image? Why does this white square even come up?
Built in editing is very limited. Here is what the Apple documentation says:
Editing controls To specify whether the camera interface should offer
the user controls for moving and scaling the captured picture, or for
trimming the captured movie, set the allowsEditing property to YES (to
provide editing controls) or to NO.
When using built-in editing controls, the image picker controller
enforces certain options. For still images, the picker enforces a
square cropping as well as a maximum pixel dimension. For movies, the
picker enforces a maximum movie length and resolution. If you want to
let the user edit full-size media, or specify custom cropping, you
must provide your own editing UI.
Make sure you're not enable editing for the UIImagePickerController.
You just need this:
UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePicker setDelegate:self];
[controller presentModalViewController:imagePicker animated:YES];
[imagePicker release];
Related
I'm using below code.
self.picker=[[UIImagePickerController alloc] init];
self.picker.delegate=self;
self.picker.allowsEditing=NO;
self.picker.sourceType=UIImagePickerControllerSourceTypeCamera;
self.picker.cameraOverlayView=[self addCameraRollButton];
[self presentViewController:self.picker animated:NO completion:NULL];
How to take picture from camera without going to Usephoto page. I want to stay on camera view. I'm not able to get camera spinner action.I used custom overlay but in that Square focus not coming.Please help me.I want all default camera features.
Once you use custom overlay you will not be able to see default camera features.If you want all default features you should use
self.picker.showsCameraControls = YES;
This opens default camera and you can see all features.
If you want to go with custom overlay then you need to built all features.
I am newbie to iOS programming.
I have a few simple questions.
After picking image from gallery or taking a picture from camera, I want to select
rectangle area like android
UIImagePickerController * picker =[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.allowsEditing=YES;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
When I use this code, I can't resize my area as you see below
.
It is related to first question.
As you see my image is resized and changed to different ratio.
But I want image is fixed with original ratio.
Anyone knows how to use camera in iOS simulator?
Question 3: You cannot use the camera function in simulator. That is one of the limitations. See this document from Apple Developer page: https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/iOS_Simulator_Guide/TestingontheiOSSimulator/TestingontheiOSSimulator.html
Question 2: below
This is answer is from this link: How to make UIImageView automatically resize to the size of the image loaded
UIImage img = [UIImage imageNamed:#"myImage.jpg"];
[imageView setImage:img];
imageView.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y,
img.size.width, img.size.height);
"This will however not change the layout of view it is contained within, you can make it change the sizes of the other views automatically under iOS 6 using Layout Constraints. If you are an Apple Developer you can watch the WWDC instruction videos, they explain how that system works quite well."
It's the best answer I have as it is the way I use setting image sizes in a view.
In someViewController:
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:^{
}];
I take a photo and get to the next screen where (due to allowsEditing = YES;) I have an option to crop my photo into square shape. White square rectangular appears on an initial position over the photo I've taken and I try to move it around. I can drag it, but every time I release the finger, it goes back to the position it held initially. The are no glitches. When I release the finger, white framed rectangular animates with easeOut animation back to the position where I dragged it from.
It is not the same as if allowsEditing is set to NO. If it is set to NO, than a cropping rectangle does not even appear.
Previously, I thought that the problem appears only on iOS 7, but now I realise that it happens on all iOS versions. I don't understand how this happened, but it started when I started using Xcode 5 and building for iOS7. I kept Xcode 4.6.3 on my Mac so I tried to build this app again with the older Xcode, but it did not fix anything.
I also need to mention that when I load an image from photo library, cropping works fine, like it is supposed to. I have problems only when taking a new photo.
Furthermore, when initial crop rectangle appears, although I am unable to drag that rectangle around the photo, I can still zoom in and out. When I zoom in, I can then drag this (smaller) cropping rectangle around the photo but ONLY within boundaries of initial rectangle's position & size. If I cross that boundary, my cropping rectangle animates back to the inside of the invisible boundaries.
Anyone, please help...
It seems like this is a bug with UIImagePickerController. I was trying to figure out what I did wrong. But then I started a couple of blank new projects just to test this functionality. I also checked out the Apple's official sample code:
https://developer.apple.com/library/ios/samplecode/photopicker/Introduction/Intro.html
I have read that it is automatic but it doesn't appear to be happening in my case. Using UIImagePickerController with allowsEditing set to YES I get my editing view with the crop square overlay, but when i am finished with the image its not cropped as I expect.
Should it be automatic at this stage? If not, what might be a good solution to crop the image in the matching area that the default view provides?
Thanks.
You are probably using the wrong key for the info dictionary: UIImagePickerControllerOriginalImage.
To get the cropped (yes, it is automatic) image you have to use UIImagePickerControllerEditedImage key.
This should do the trick:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *pickedImageEdited = [info objectForKey:UIImagePickerControllerEditedImage];
//dismiss the picker and process the image...
}
Is it possible to provide UIImagePickerController a UIIMage object, to use editing functionality provide this pickerController.
This is how I am trying to implement it.
-(IBAction) openEditor:(id) sender{
UIImagePickerController *pickerCntrl=[[UIImagePickerController alloc] init];
pickerCntrl.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
pickerCntrl.allowsEditing=YES;
[self presentViewController:pickerCntrl animated:YES completion:nil];
}
But, for this Image must be already present in the Album. Another thing is it provides a UI for you to select the Image.
I am trying to open directly the following window on openEditor:(id) sender.
The UIImagePickerController is for picking an image (either from the photo library or the camera). It can't be used for any kind of editing of any arbitrary image you wish to supply.
If you want to provide scaling and cropping of your own image then you must implement your own image editing controller.
Either implement your own or look into a 3rd party library that already does this. I've had good luck with the Aviary SDK.