This is the image with cropping option.
I want to remove this cropping option and want to upload the full length image. Is it possible using iOS imagepicker?
When I am going to upload an image from photo gallery,it shows the cropping option. I don't want the crop option. I want to upload the full image without cropping it.How to remove that cropping option? Is it possible? Please help. I have used the following code but it's not working:
@IBAction func clickImageUpload(_ sender: Any)
{
let actionSheet = UIAlertController(title: nil, message: "Choose an Option", preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Choose from Gallery", style: .default, handler: {
(alert: UIAlertAction!) -> Void in
self.imagePickerController.allowsEditing = true
self.imagePickerController.sourceType = UIImagePickerControllerSourceType.photoLibrary
self.imagePickerController.delegate = self
self.present(self.imagePickerController, animated: true, completion: nil)
}))
actionSheet.addAction(UIAlertAction(title: "Take a Photo", style: .default, handler: {
(alert: UIAlertAction!) -> Void in
if UIImagePickerController.isSourceTypeAvailable(.camera) {
self.imagePickerController.allowsEditing = true
self.imagePickerController.sourceType = UIImagePickerControllerSourceType.camera
self.imagePickerController.delegate = self
self.present(self.imagePickerController, animated: true, completion: nil)
}
else{
print("No camera")
}
}))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(actionSheet, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
let image = info[UIImagePickerControllerEditedImage] as! UIImage
imgvwProfile.contentMode = .scaleAspectFit
imgvwProfile.image = image.squareMe()
//imgvwProfile.image = image
self.imageData = UIImageJPEGRepresentation(self.imgvwProfile.image!, 1.0)!
print(imageData)
print(info)
//obtaining saving path
if let assetPath = info[UIImagePickerControllerReferenceURL] {
if ((assetPath as! NSURL).absoluteString?.hasSuffix("JPG"))! {
print("JPG")
extensionType = "jpg"
}
else if ((assetPath as! NSURL).absoluteString?.hasSuffix("PNG"))! {
print("PNG")
extensionType = "png"
}
else if ((assetPath as! NSURL).absoluteString?.hasSuffix("GIF"))! {
print("GIF")
extensionType = "gif"
}
else {
print("Unknown")
//extensionType = "Unknown"
}
}
if extensionType.count == 0 {
extensionType = "jpg"
}
let fileManager = FileManager.default
let documentsPath = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first
print("IMAGE= \(documentsPath)")
let imagePath = documentsPath?.appendingPathComponent("image.png")
self.idProofDic["data"] = self.imageData as! Data
self.idProofDic["mimeType"] = "image/\(extensionType)"
self.idProofDic["extension"] = ".\(extensionType)"
dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}
您可以使用默认控件禁用图像裁剪。
self.imagePicker.allowsEditing = false
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.