Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/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
C# 如何在c语言中将图像转换成字符串?尤其是在单触式ios中_C#_Image_Xamarin.ios - Fatal编程技术网

C# 如何在c语言中将图像转换成字符串?尤其是在单触式ios中

C# 如何在c语言中将图像转换成字符串?尤其是在单触式ios中,c#,image,xamarin.ios,C#,Image,Xamarin.ios,我是c的新手。我正在开发一个iOS项目。我想上传图像到服务器。所以我想把图像转换成字符串。有人能帮我做这件事吗 我同意任何上传图像到服务器的方法。怎么样 FileStream stream = new FileStream(imageFilePath, FileMode.Open); BinaryReader binreader = new BinaryReader(stream); byte[] buffer = new byte[(int) stream.Length]; buffer =

我是c的新手。我正在开发一个iOS项目。我想上传图像到服务器。所以我想把图像转换成字符串。有人能帮我做这件事吗

我同意任何上传图像到服务器的方法。

怎么样

FileStream stream = new FileStream(imageFilePath, FileMode.Open);
BinaryReader binreader = new BinaryReader(stream);
byte[] buffer = new byte[(int) stream.Length];
buffer = binreader.ReadBytes((int) stream.Length);
string serialized = Convert.ToBase64String(buffer)
如果使用System.Drawing.Image对象而不是文件路径,则可以执行以下操作:

System.Drawing.Image image; //initialize it someway
MemoryStream ms = new MemoryStream();
image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg); //if it is jpeg
byte[] buffer = ms.ToArray();
string serialized = Convert.ToBase64String(buffer);
然后将“序列化”值传递给服务器


Put是否工作取决于服务器如何处理它。

同样的,只是代码少了一点

//Clientside    
byte[] imgBytes = File.ReadAllBytes("FilePath");
string imgStr = System.Convert.ToBase64String(imgBytes);

//Serverside 
byte[] serverSideImgBytes = System.Convert.FromBase64String(imgStr);
File.WriteAllBytes("PathAndFileName", serverSideImgBytes);

读这个@aberna,我想从我的iOS应用程序上传图片到php。这是主要问题。我会检查这个。谢谢,我有一些人类看不懂的东西。可以如何将其发送到php服务器?您好,heringer,请告诉我,我必须将哪个发送到服务器?您是否已将imagefilepath转换为图像?不需要转换图像?请解释。我听不懂。请看编辑后的答案。我在尝试第二种方法时出现了两个错误。错误是我不能使用System.Drawing.ImageView.Image。我的意思是,我在ImageView上有图像。如何将其设置为system.drawing?第二个错误是“保存”没有任何定义。如何解决这个问题?引导我heringer.server是php。。如何将这些代码应用到php?我想你们可以使用php函数base64_decodeguys,你们都教我如何转换文件路径。我不需要转换文件路径。我只需要转换图像。不是它的路径。请理解。替换图像路径上的文件路径,如../Images/Picture.jpg。当您将图像字节发送到服务器时,请发送文件名进行保存。