Decode Base-64 encoded PNG in an NSString(在 NSString 中解码 Base-64 编码的 PNG)
问题描述
我有一些 NSData
是 Base-64 编码的,我想对其进行解码,我看到了一个看起来像这样的示例
I have some NSData
which is Base-64 encoded and I would like to decode it, I have seen an example that looks like this
NSData* myPNGData = [xmlString dataUsingEncoding:NSUTF8StringEncoding];
[Base64 initialize];
NSData *data = [Base64 decode:img];
cell.image.image = [UIImage imageWithData:myPNGData];
然而,这给了我很多错误,我想知道如何才能让它工作.我需要将某种类型的文件导入到我的项目中还是必须包含框架?
However this gives me a load of errors, I would like to know what to do in order to get this to work. Is there some type of file I need to import into my project or do I have to include a framework?
这些是我得到的错误
Use of undeclared identifier 'Base64'
Use of undeclared identifier 'Base64'
Use of undeclared identifier 'cell'
我到处找,不知道什么是正确的做法.
I have looked everywhere and cannot figure out what is the proper thing to do.
推荐答案
NSData Base64 库文件 会帮助你.
#import "NSData+Base64.h"
//Data from your string is decoded & converted to UIImage
UIImage *image = [UIImage imageWithData:[NSData
dataFromBase64String:strData]];
希望对你有帮助
Swift 3 版本
几乎一样
//Create your NSData object
let data = NSData(base64Encoded: "yourStringData", options: NSData.Base64DecodingOptions.ignoreUnknownCharacters)
//And then just create a new image based on the data object
let image = UIImage(data: data as! Data)
Swift 2.3 版本
//Create your NSData object
let data = NSData(base64EncodedString: "yourStringData", options: .IgnoreUnknownCharacters)
//And then just create a new image based on the data object
let image = UIImage(data: data!)
这篇关于在 NSString 中解码 Base-64 编码的 PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 NSString 中解码 Base-64 编码的 PNG
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01