I do not know how to make it use multiple cores, but to make it thread safe, you need to do the following. First declare a closed static object
private static readonly Object _obj = new Object();
Then change your code as below:
public static byte[] ImageToByte(Image img)
{
lock(_obj)
{
byte[] byteArray = new byte[0];
using (MemoryStream stream = new MemoryStream())
{
img.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
stream.Close();
byteArray = stream.ToArray();
}
return byteArray;
}
}
source
share