前端之家收集整理的这篇文章主要介绍了
Swift 图像转换为Base64字符串,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
let filePath = NSBundle.mainBundle().pathForResource("test",ofType: "jpg")
let data = NSData(contentsOfFile: filePath!)
let base64 = data!.base64EncodedStringWithOptions(.EncodingEndLineWithLineFeed)
let image = UIImage(named:"imageNameHere")!
let imageData = UIImagePNGRepresentation(image)
let base64 = imageData!.base64EncodedStringWithOptions(.EncodingEndLineWithCarriageReturn)
let url = NSURL(string : "urlHere")!
let imageData = NSData(contentsOfURL: url)
let base64String = imageData!.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
let decodedData = NSData(base64EncodedString: base64String,options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters)
原文链接:https://www.f2er.com/swift/322410.html