I wanted to use UIImagePickerController to select an image, crop it to a given size (using a given aspect ratio) and to set it on my UIImageView.
So I did the following:
let picker = UIImagePickerController();
picker.modalPresentationStyle = .currentContext;
picker.allowsEditing = true;
picker.delegate = self;
self.present(picker, animated: true);
When I know try it I can select an image and I get leaded to the "move and scaling" view of iOS. But actually.... I have no crop frame and also moving and scaling is a little bit "strange" and it does not matter how I move or scale the image, the result is always the same. The result is always just showing a small section of the original picture (top left corner).
So what is the editing mode good for at all if it has zero functionality?
Related
UIImagePickerController* libraryUI = [[UIImagePickerController alloc] init];
libraryUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
libraryUI.delegate = self;
libraryUI.allowsEditing = YES;
[self presentViewController:libraryUI animated:YES completion:nil];
I am using this code to open image picker view and pick an image from gallery. I also set the property "allowsEditing" to "YES" in order to enable the crop image functionality. Now the main issue is that the picker view opened with rectangular crop option. What I want is to get circular crop image option and also want to set the crop circle size (increase or decrease crop circle size).
Since it is not available by default, I will suggest you to use this library:
TOCropViewController
It comes with some other features other than circular crop as well. Objective-C and Swift versions are both available
I am trying to have my application take a photo of an "intruder" when the wrong pin is entered into my application.
I have set up the UIImagePickerController(Below) and can make the application display the camera and take photos with no problem what so ever.
picker = UIImagePickerController() //make a clean controller
picker.delegate = self
picker.allowsEditing = false
picker.sourceType = UIImagePickerControllerSourceType.Camera
picker.cameraCaptureMode = .Photo
presentViewController(picker,animated: true,completion: nil)
Then i proceed to attempt this as to make the new set up for the picker
picker.showsCameraControls = false
I know that has to be set to false to call picker.takePicture()
Now I dont want to present the picker viewController and be able to call takePicture() but this is not hitting the delegate method of didFinishPickingMediaWithInfo.
I have tried using a custom overlay as well, but to no avail of 100% hiding the camera.
How do I go about not showing or displaying the camera on screen and being able to grab this picture of the front camera?
I have permission for access as well.
The other question posted on here of a similar topic does not solve this issue for help in swift.
Is the only way possible using AVFoundation?
If so, any help would be appreciated
In my view I have a UIView that I use to preview the camera. It's a lot smaller than the regular preview view (128x128). I initialise the UIImagePickerController like this:
self.picker = [[UIImagePickerController alloc] init];
self.picker.delegate = self;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
self.picker.showsCameraControls = NO;
self.picker.view.frame = self.profilePictureView.frame;
I then use [v addSubview:self.picker.view]; to show the camera's preview within my custom UIVIew. So far this works as intended, I see the part of the camera preview that overlaps my custom view in that view (essentially masking the preview with my custom view).
Now I'm trying to get what is displayed in my UIView into a UIImage (resulting in a 128x128 image). I tried using the delegation methods, but I only get the full size image from the camera there. I also tried taking a screenshot from the view but I got lost...
How can I create a UIImage with the exact same content as the view I use to render the camera preview, including size, offset and ratio?
I'm trying to present a camera on the only the top half of my screen and my code isn't resizing the camera properly. I'm trying to add a view to the top half of my screen and then have the camera's cameraOverlayView property conform to that view's frame. Regardless of what I try however, the camera still appears in full screen mode. If someone can tell me what I'm doing wrong I'd really appreciate it. Thanks!
// Setting Up The Camera View
cameraView = UIView(frame: CGRectMake(0.0, 0.0, view.bounds.width, view.bounds.width))
view.addSubview(cameraView)
// Setting Up The Camera
var cam = UIImagePickerController()
cam.delegate = self
cam.allowsEditing = false
cam.videoMaximumDuration = 7
cam.videoQuality = UIImagePickerControllerQualityType.TypeMedium
cam.mediaTypes = UIImagePickerController.availableMediaTypesForSourceType(UIImagePickerControllerSourceType.Camera)!
cam.sourceType = UIImagePickerControllerSourceType.Camera
cam.cameraDevice = UIImagePickerControllerCameraDevice.Rear
cam.cameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video
cam.cameraFlashMode = UIImagePickerControllerCameraFlashMode.Off
cam.showsCameraControls = true
cam.cameraOverlayView = cameraView
cam.cameraOverlayView?.frame = cameraView.frame
camera = cam
self.presentViewController(camera, animated: false, completion: nil)
I do not think what you want to do can be accomplished using a UIImagePickerController. The AVFoundation is what you want to use if you want complete customization of the camera. You can read about it here https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW2.
P.S. It is not the simplest framework to use
I am using the IOS standard image cropping functionality (move and scale) to crop my image before submitting it to the server.
However, I realize that the cropping provided has a square ratio (see screenshot below)
Snippet of the code is as follows:
//set up image picker
self.imgPicker = [[[UIImagePickerController alloc] init]autorelease];
self.imgPicker.allowsEditing = YES;
self.imgPicker.delegate = self;
//Trigger get photo from library function
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:self.imgPicker animated:YES];
How can allow 'move and scale' editing and at the same time allow the user to do cropping WITHOUT the square ratio restriction?
I think you need change self.imgPicker.allowsEditing = YES; to self.imgPicker.allowsEditing = NO;
This library can help you.
https://github.com/gekitz/GKImagePicker
It supports custom cropping and it's easy to integrate with the native picker if needed.
I think , this will serve your purpose . You can change the constraints as you want
https://github.com/kishikawakatsumi/PEPhotoCropEditor?source=cc