简体   繁体   English

使用Xamarin形式将图像转换为字节以用于iPhone应用程序

[英]Convert image to byte for iphone application using xamarin forms

I want to convert an image to bytes for server upload. 我想将图像转换为字节以供服务器上传。 So, I have used the below code which is throwing error. 所以,我用下面的代码抛出错误。 Can anyone please help me out? 有人可以帮我吗?

Error: “Reference to type 'system.componentmodel.typeconverter' claims it is defined assembly system but it could not be found". 错误:“对类型'system.componentmodel.typeconverter'的引用声称它是定义的组装系统,但找不到。”

public static byte[] imgToByteConverter(System.Drawing.Image inImg)
{
    ImageConverter imgCon = new ImageConverter();   
    return (byte[])imgCon.ConvertTo(inImg, typeof(byte[]));        
}

A Xamarin Form Image is not the same as a System.Drawing.Image. Xamarin表单图像与System.Drawing.Image不同。 System.Drawing.Image is a W32 class and does not exist in Xamarin. System.Drawing.Image是W32类,在Xamarin中不存在。 You can't convert a XF image to a byte[]. 您不能将XF图像转换为byte []。 Instead, you need to refer to whatever resource (file, stream, url, etc) was used to create the Image and use that to create the byte[]. 相反,您需要引用用于创建映像的任何资源(文件,流,URL等),然后使用该资源创建byte []。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM