【发布时间】:2011-06-06 16:17:00
【问题描述】:
我想使用 .NET 网络服务上传图片,这将从 iphone 图片中调用。
iphone 发送给我的文本格式是这样的。
http://d8768157.u118.c6.ixwebhosting.com/iphoneimg/image.txt
我必须将此数据转换为哪种数据类型,然后以图像格式保存。
如果您有其他方法,请告诉我。
我尝试在 byte[] 中转换此数据,但它给了我错误。这是我的代码。对于我所尝试的。请帮帮我。
[WebMethod]
public XmlDocument testuploadimage(string image)
{
XmlDocument login = new XmlDocument();
XmlDeclaration dec = login.CreateXmlDeclaration("1.0", null, null);
login.AppendChild(dec);
XmlElement root = login.CreateElement("CreateUser");
login.AppendChild(root);
try
{
string actFolder = Server.MapPath("~/iphoneimg/");
string imgname = DateTime.UtcNow.ToString().Replace(" ", "").Replace("AM", "").Replace("PM", "").Replace("/", "").Replace("-", "").Replace(":", "") + ".png";
Bitmap map;
using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(image)))
using (FileStream fs = File.Create(actFolder + imgname))
{
map = (Bitmap)Image.FromStream(stream);
map.Save(fs, System.Drawing.Imaging.ImageFormat.Gif);
}
XmlElement root1 = login.CreateElement("uploaded");
root1.InnerText = "true";
root.AppendChild(root1);
XmlElement root2 = login.CreateElement("path");
root2.InnerText = "http://d8768157.u118.c6.ixwebhosting.com/iphoneimg/" + imgname;
root.AppendChild(root2);
return login;
}
catch (Exception ex)
{
throw ex;
}
}
这是我遇到的错误
Base-64 字符串中的无效字符。
谢谢
BHAVIK GOYAL
【问题讨论】:
-
您能否添加您收到的错误消息?堆栈跟踪也是如此?
-
@Jonathan 我已更新错误。
标签: c# iphone .net web-services base64