1

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".

public static byte[] imgToByteConverter(System.Drawing.Image inImg)
{
    ImageConverter imgCon = new ImageConverter();   
    return (byte[])imgCon.ConvertTo(inImg, typeof(byte[]));        
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
gunas
  • 1,889
  • 1
  • 16
  • 29

1 Answers1

0

A Xamarin Form Image is not the same as a System.Drawing.Image. System.Drawing.Image is a W32 class and does not exist in Xamarin. You can't convert a XF image to a 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[].

Jason
  • 86,222
  • 15
  • 131
  • 146