UIImagePickerController图像类型在swift 3中

时间:2017-08-10 14:22:39

标签: iphone swift3 uiimagepickercontroller xcode8.2

我正在使用UIImagePickerController从图库和相机中选择图像。我正在使用以下代表

    public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
    imageView = info[UIImagePickerControllerEditedImage] as! UIImage
    profilePhoto.contentMode = .scaleAspectFill
    profilePhoto.image = imageView
    let imageData: Data =  UIImagePNGRepresentation(profilePhoto.image!)!
    self.base64String = imageData.base64EncodedString()
    dismiss(animated:true, completion: nil)
  }

  public func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    print("Cancel")
  }

我在配置文件视图中成功设置了图像。但我需要知道通过图库和摄像机选择的图像的格式,即它是.jpeg还是.png,因为我需要将类型发送到后端。请告诉我们如何知道图像的格式

1 个答案:

答案 0 :(得分:0)

对于相机,您可以决定使用 让jpgImage = UIImageJPEGRepresentation(imageView,1.0) 和 让pngImage = UIImagePNGRepresentation(imageView)