ios - 如何在 iOS/swift 中上传图像时删除裁剪选项

标签 ios swift

这是带有裁剪选项的图像。

enter image description here

我想删除此裁剪选项并上传完整长度的图像。是否可以使用 iOS imagepicker?

当我要从照片库上传图像时,它会显示裁剪选项。我不想要裁剪选项。我想上传完整图像而不裁剪它。如何删除该裁剪选项?是否可以?请帮忙。 我使用了以下代码,但它不起作用:

 @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

关于ios - 如何在 iOS/swift 中上传图像时删除裁剪选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55824531/

相关文章:

iOS 火猴 : How to send email from iOS App though mail app in Firemonkey Delphi XE7

iOS 为什么系统在后台使用位置杀死应用程序

ios - 如何在xcode 11.3.1中添加XR模拟器

swift - 无法以编程方式调整约束

ios - 使用 compass Swift 指向位置

ios - UIImageView 无法正确居中

ios - 图片的异步下载

iphone - 在 phonegap 项目中停止 iframe 重定向/打开移动 safari

ios - 二元运算符 '+' 不能应用于类型 'Double' 和 'Element' (又名 'AnyObject' )的操作数

iOS MapView无法配合GPS服务