iPhone SDK中如何将NSData转换为字符串?
我正在开发一个 iPhone 应用程序,其中相机图像通过 UIImageJPEGRepresentation
存储在 NSData
中,现在我想将此 NSData 转换为字符串。经过一番研究,我发现 base64 可以做到这一点。
我想知道,如果我将其编码为base64,然后将其发送到php服务器,那么就可以对其进行解码并转换为图像。
我首先在这里询问这里 如何将带有坐标和图像描述的图像发送到php服务器,但我无法得到响应,所以现在我想将图像转换为base64,然后将其发送到带有坐标和图像描述的php服务器。
希望有人知道解决办法!
I am developing an iPhone application in which camera image store in NSData
through UIImageJPEGRepresentation
now i want to convert this NSData into string. After goggling I found base64 will do this.
I want to know that if i encode it into base64 and then send it to php server, then it is possible to decode it and convert into Image.
I first ask here how to send Image with coordinates and image description to php server but i cannot got response, so now i think to convert image into base64 and then send it to php server with coordinates and image description.
Hope someone know the solution !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这对我来说听起来不太好。一些 http 客户端对图像上传提供了很好的支持。查看 ASIHttpRequest。您可以将数据保存到临时文件,然后上传该文件。我之前没有使用addData方法,看起来你可以直接上传NSData对象。
That doesn't sound good to me. Some http clients provide nice support for image upload. Take a look at ASIHttpRequest. You can save the data to a temp file then upload that file. I didn't use addData method before, looks like you can upload NSData object directly.
看看下面的网址。它可能会给你你正在寻找的东西。
http://www .iphonedevsdk.com/forum/iphone-sdk-development/49247-posting-image-web-server-using-soap.html
Take a look at the following url. It may give you what you are looking for.
http://www.iphonedevsdk.com/forum/iphone-sdk-development/49247-posting-image-web-server-using-soap.html
Base64 是一种标准,并且受到包括 PHP 在内的大多数语言的支持,因此它可以工作。
但这可能不是最好的方法,因为 base64 将有效负载大小增加了 33%。您应该考虑将其作为二进制而不是字符串发送,这也将更好地支持流式传输,并且将使用更少的内存并且在客户端和服务器上工作得更快。
您应该仅在小数据或没有更好的选择时使用 base64。
Base64 is a standard and is supported by most languages including PHP, so it would work.
But this is probably not the best way to do it, as base64 increases the payload size by 33%. You should look into sending it as binary and not string, this will also better support streaming and will use less memory and work faster both on client and server.
You should use base64 only on small data or when there are no better options.
按照此代码将图像和变量发送到服务器 -
follow this code to send images and variables to server -