Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift ';额外的参数称为';使用DocumentCamera扫描后调整图像大小时_Swift_Uiimage - Fatal编程技术网

Swift ';额外的参数称为';使用DocumentCamera扫描后调整图像大小时

Swift ';额外的参数称为';使用DocumentCamera扫描后调整图像大小时,swift,uiimage,Swift,Uiimage,请帮助我将图像调整为用户设置的尺寸。我目前正在使用swift documentscanner扫描文档,然后将其保存到相机。进行此操作时,我希望用户在扫描后设置尺寸。我遇到过许多调整大小的功能,但它们似乎都不起作用。在保存图像之前,我尝试使用以下代码调整图像大小 调用函数时: for i in 0...scan.pageCount-1 { let originalImage = scan.imageOfPage(at: i)

请帮助我将图像调整为用户设置的尺寸。我目前正在使用swift documentscanner扫描文档,然后将其保存到相机。进行此操作时,我希望用户在扫描后设置尺寸。我遇到过许多调整大小的功能,但它们似乎都不起作用。在保存图像之前,我尝试使用以下代码调整图像大小

调用函数时:

  for i in 0...scan.pageCount-1 {
                            let originalImage = scan.imageOfPage(at: i)
                            self.resizeImagez(image: originalImage, newWidth: Widthv, Heightv)///Where the Extra Argument called error comes
                            let fixedImage = originalImage.jpegData(compressionQuality: 0.5)
                            let reloadedImage = UIImage(data: fixedImage!)
                            UIImageWriteToSavedPhotosAlbum(reloadedImage!, nil, nil, nil);
职能:

  func resizeImagez(image: UIImage, newWidth: CGFloat) -> UIImage {

        let scale = newWidth / image.size.width
        let newHeight = image.size.height * scale
        UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight))
        image.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: newHeight))
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

        return newImage!
    }
用户输入其尺寸时:

         // Alert action confirm
           let confirmAction = UIAlertAction(title: "OK", style: .default, handler: {(_ action: UIAlertAction) -> Void in
              // print("name: \(String(describing: alertController.textFields?[0].text))")
               //print("email: \(String(describing: alertController.textFields?[1].text))")
            
            let widthhh =  alertController.textFields![0].text!
            let  heighthg = alertController.textFields![1].text!
            if let n = NumberFormatter().number(from: widthhh) {
                self.Widthv = CGFloat(truncating: n)
             }
            if let l = NumberFormatter().number(from: heighthg) {
                self.Heightv = CGFloat(truncating: l)
             }
           })
           alertController.addAction(confirmAction)

           // Alert action cancel
           let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: {(_ action: UIAlertAction) -> Void in
               print("Canelled")
           })
           alertController.addAction(cancelAction)

           // Present alert controller
           present(alertController, animated: true, completion: nil)
    }

不要介意这个名字,因为我很容易就能认出它。 如果你还需要什么,请在评论中告诉我


提前谢谢

看起来你要传递的额外参数是“Heightv”。如果你去掉这个,看起来你传递的额外参数是“Heightv”。如果你把它拿走呢