Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何获取图像的有效base64字符串_Ios_Objective C_Xcode_Ios7 - Fatal编程技术网

Ios 如何获取图像的有效base64字符串

Ios 如何获取图像的有效base64字符串,ios,objective-c,xcode,ios7,Ios,Objective C,Xcode,Ios7,我使用以下代码获取图像的base64编码字符串: UIImage *image = [photoView image]; NSString *encoded = [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]; 图像是800*800像素,但生成的字符串太大,当我将其粘贴到文本框中时,它会使浏览器崩溃。我在dreamweaver中粘

我使用以下代码获取图像的base64编码字符串:

UIImage *image = [photoView image];
NSString *encoded = [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
图像是800*800像素,但生成的字符串太大,当我将其粘贴到文本框中时,它会使浏览器崩溃。我在dreamweaver中粘贴了它来计算行数,它超过了300000行。这不可能是对的。如果我上传相同的图片,它会生成一个大约200行的base64字符串

如何在目标c中生成“普通”base64字符串?一个我可以用的


正如Martin R所建议的,我检查了UIImagePNGRepresentation(image)返回的数据长度,它是4502370字节。这可能是问题的一部分。是否在UIImageView中绘制图像并稍后像我这样检索图像会返回屏幕大小的图像?

通过使用
nsdatabase64编码64字符linelength
将每行限制为64个字符(如文档中所述)。尝试:


base-64编码字符串是二进制数据大小的1.37倍。因此:

800x800x4(32位RGBA)=2560000字节

x 1.37=3507200字节


我不明白您为什么要将base-64编码字符串粘贴到浏览器中?

您可以尝试:uiImageJPEGresentation(图像,0.9f)为什么不从
NSData*data=UIImagePNGRepresentation(图像)
开始并选中
[数据长度]
隔离问题?…因此这不是Base64编码器的问题。@MartinR确实,我正在从相机检索图像,然后重新缩放,但似乎没有正确地重新缩放。image.size被适当地缩小到800*800,但数据长度在重新缩放后会增加……您看到的任何差异都可能是压缩上的差异。我这样做是为了计算行数,之前我使用了NSDatabase64 EncodingEndlineWithCarineReturn。现在我将尝试使用0。我正在将其粘贴到base64解码器联机中,以查看是否成功。
UIImagePNGRepresentation()
返回PNG数据,而不是原始数据。当然,如果图像压缩得不好,也可能同样大。当然,PNG被认为是压缩的,尽管压缩的量变化很大。@MartinR当然,关键是,结果字符串总是太大,无法粘贴到任何你喜欢的地方。而且目前还不清楚OP提到的网站上正在进行哪种图像压缩。
NSString *encoded = [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:0];