简体   繁体   English

快速从UIImage获取字符串

[英]get a string from UIImage in swift

I have image loaded from UIImagePickerController into UIImageView 我已将图像从UIImagePickerController加载到UIImageView

I need to convert the image into string to send it to the server 我需要将图像转换为字符串以将其发送到服务器

This is my code but it gives an error 这是我的代码,但它给出了一个错误

var imageData:String = "";
        if let unwrappedImage = profileImage.image {
            let imageNSData : NSData = UIImageJPEGRepresentation(unwrappedImage, 1.0)!;
            imageData =  (NSString(data:imageNSData, encoding:NSUTF8StringEncoding) as String?)!
        }

I am getting the following exception 我收到以下异常

fatal error: unexpectedly found nil while unwrapping an Optional value

can any one help please 有人可以帮忙吗

Convert the data information of a image to a string , you will get a very very very long string, why not loaded the data to the server. 将图像的数据信息转换为字符串,您会得到一个非常非常长的字符串,为什么不将数据加载到服务器。 Alamofire can do it easily, just see the uploading file part. Alamofire可以轻松做到这一点,只需查看上传文件部分即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM