在swift中从UIImage获取一个字符串

时间:2022-12-03 00:03:02

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

请任何人帮忙

1 个解决方案

#1


0  

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可以轻松完成,只需查看上传文件部分即可。

#1


0  

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可以轻松完成,只需查看上传文件部分即可。