如何在c#中将图像转换为字符串?特别是在Monotouch ios中 [英] how to convert image into string in c#? Especially in Monotouch ios
本文介绍了如何在c#中将图像转换为字符串?特别是在Monotouch ios中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是c#的新手。我正在开发一个iOS项目。我想将图像上传到服务器。所以我想将图像转换为字符串。任何人都可以帮我这样做。
I am new to c#. I am developing an iOS project. i want to upload images to server. So i want to convert image into string. can anyone help me to do this.
我同意将图像上传到服务器的任何方法。
I am agree any type of method to upload image to sever.
推荐答案
那怎么样?
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。图像对象而不是文件路径,你可以这样做:
If you have the System.Drawing.Image object instead of a file path, you can do:
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);
然后将'serialiazed'值传递给服务器。
And then you pass the 'serialiazed' value to the server.
如果它能够起作用取决于服务器将如何处理它。
Put if it will work depends on how the server will handle that.
这篇关于如何在c#中将图像转换为字符串?特别是在Monotouch ios中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文