我正在通过 wcf 从 monotouch 连接到我的 Windows C# 主机,并希望将图像流式传输回 monotouch,以便我可以显示它。
我的图像保存在 System.Drawing.Image 对象中,该对象在单触摸中不可用(它使用 UIImage)。
我希望将主机上的图像转换为如下字符串:
Image im = Image.FromFile(path);
MemoryStream ms = new MemoryStream();
im.Save(ms, im.RawFormat);
byte[] array = ms.ToArray();
return Convert.ToBase64String(array);
然后在 MonoTouch 中使用相反的方法来再次恢复我的图像:
byte[] array = Convert.FromBase64String(imageString);
Image image = Image.FromStream(new MemoryStream(array));
return image;
这在“纯”.net 环境中工作正常,但 monotouch 无法识别 Image 对象,因此它会失败。 如何将 byte[] 转换回 UIImage?
我尝试过这样的事情:
UIImage img = (UIImage)UIImage.FromObject(bytes);
没用...
非常感谢任何帮助!
最佳答案
不要传递 im.RawFormat
,而是尝试使用以下之一:
ImageFormat.Bmp
ImageFormat.Png
取决于您的图像通常采用的格式。这些位于 System.Drawing.Imaging 中,see here .
这可能会给其他客户端应用程序带来麻烦,我建议让客户端发送一些内容来确定服务器返回的格式。
关于image - 如何将 C# 图像转移到 Monotouch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10718881/