Don't convert it to a string - convert it to a byte array. Strings have a default conversion which you do not want for image data, bytes don't. Most databases have a VarBinary as well as a VerChar which is designed to hold such data.
Then convert the image to bytes:
public static byte[] ImageToByte(Image img)
{
ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}
If your framework doesn't the include ImageConverter class (and I don't know if it does) you can convert it by writing the image to a stream, and then using the Stream.ToArray method but that is quite a bit less efficient.
"i tried this, but it is giving an exception
ConvertTo not implemented in base TypeConverter.
what should i do.
and also,
how can i convert this byte array back to image."
That probably means it isn't implemented in your framework - not everything is in the mobile frameworks. You can go via the messier stream though:
public static byte[] ImageToByteStream(Image img)
{ byte[] data = new byte[0];
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
ms.Seek(0,0);
data = ms.ToArray();
}
return data;
}
It is probably best if you reverse the process to go back to an image using the Bitmap.FromStream method.