我创建了一个应用程序来获取图像并将此图像转换为二进制文件并发送到服务器。我拍摄的图片却无法转换。
我使用此代码:
func cameraa(){
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .Camera
presentViewController(picker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
ImageDisplay.image = info[UIImagePickerControllerOriginalImage] as? UIImage;dismissViewControllerAnimated(true, completion: nil)
}
@IBAction func Encode(sender: UIButton) {
var imageEncode = ImageDisplay.image
let image : UIImage = UIImage(imageEncode)
let imageData = UIImagePNGRepresentation(image)
print(imageData)
我在解析图片(imageEncode)中的错误(让图片:UIImage = UIImage(imageEncode))
答案 0 :(得分:2)
ImageDisplay.image
已经是UIImage
。因此,您无需再次将其转换为UIImage
。就这样做:
let imageData = UIImagePNGRepresentation(ImageDisplay.image)
print(imageData)