我正在使用UIImagePickerController来允许用户拍照。我想让他之后编辑它,但无论我做什么,我什么也得不到。这是我的代码(我正在使用Xamarin):
UIImagePickerController imagePicker = new UIImagePickerController ();
// set our source to the camera
imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
// set what media types
//imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.Camera);
// show the camera controls
imagePicker.ModalPresentationStyle = UIModalPresentationStyle.CurrentContext;
imagePicker.ShowsCameraControls = true;
imagePicker.AllowsEditing = true;
imagePicker.SetEditing (true,true);
imagePicker.PreferredContentSize = new SizeF(900,600);
imagePicker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo;
imagePicker.Title="taste.eat. image";
// attach the delegate
imagePicker.Delegate = new ImagePickerDelegate();
// show the picker
NavigationController.PresentViewController(imagePicker, true,null);
我错过了什么吗?
修改
我已按照教程进入屏幕,但是如果我平移或缩放它,只要我抬起手指就会快速回到中心。是否可以从照片应用程序进入此屏幕?
答案 0 :(得分:39)
使用UIImagePickerController's delegate
时
方法 - imagePickerController:didFinishPickingMediaWithInfo:
,我们使用
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
即使编辑为ON,此代码也将始终返回原始图像。
尝试使用
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
如果编辑为ON,将返回编辑过的图像。
希望这有帮助。
答案 1 :(得分:22)
如果选择图片,AllowsEditing
属性只允许用户裁剪为正方形,如果选择视频则修剪视频。
需要使用自定义UI和代码实现任何其他功能。
请参阅此问题:iPhone SDK - How to customize the crop rect in UIImagePickerController with allowsEditing on?
不幸的是,您在屏幕截图中显示的内容不属于UIImagePickerController
答案 2 :(得分:6)
SWIFT 3
我很难恢复裁剪的图像(我最后的错误)。而不是使用UIImagePickerControllerOriginalImage,您需要UIImagePickerControllerEditedImage。见下文:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// The info dictionary contains multiple representations of the image, and this uses the cropped image.
let selectedImage = info[UIImagePickerControllerEditedImage] as! UIImage
// Set yourImageView to display the selected image.
yourImage.image = selectedImage
// Dismiss the picker.
dismiss(animated: true, completion: nil)
}
答案 3 :(得分:1)
它会像这样工作。
<dp-date-picker></dp-date-picker>
答案 4 :(得分:0)
仅通过更改enable filters
等属性无法allowsEditing = YES
。它只会显示裁剪工具。根据你的截图,看起来你已经集成了一些有缺陷的开源库,而且没有查看源代码,就很难修复你的中心裁剪错误。
最好发布有关您的实施的一些具体细节,或切换到standard open source library。
答案 5 :(得分:0)
SWIFT 4 +
Swift 4之后发生了一些变化。UIImagePickerControllerEditedImage
更改为UIImagePickerController.InfoKey.editedImage
。
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let selectedImage = info[UIImagePickerController.InfoKey.editedImage] as! UIImage
imageView.image = selectedImage
dismiss(animated: true, completion: nil)
}