It might be that this question has been answered before, but I found no good solution to my problem.
I am trying to convert a Bitmap to a bytearray using a memory stream, but when I do so I get an out of memory exception, and I can't figure out where and what is going wrong. Below you can find my code, and I would be very grateful for any insight on the topic.
static byte[] convertBmpToByteArray(string imageFilePath)
{
Bitmap bmpImg = (Bitmap)Bitmap.FromFile(imageFilePath);
try
{
using (MemoryStream ms = new MemoryStream())
{
bmpImg.Save(ms, ImageFormat.Bmp);
return ms.ToArray();
}
} catch(Exception e)
{
Console.WriteLine(e.StackTrace);
return null;
}
}