simple question that I simply can't seem to find a decent answer for.
i'm trying to convert a memory image to a byte array in order to upload it as a Base64String
Bitmap CapSc()
{
using(Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using(Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
return bitmap;
}
}
Image toUpload;
toUpload = (Image)CapSc();
public static byte[] GetBytesFromImage(Image img)
{
if (img == null) return null;
using (MemoryStream stream = new MemoryStream())
{
img.Save(stream, img.RawFormat);
return stream.ToArray();
}
}
GetBytesFromImage(toUpload);
however the 'img.Save' constantly returns errors where it seems to require a third paramater of EncoderParamaters, no sample code or developer solutions on MSDN say this is neccessary but it constantly returns errors if i have it present or not.
the specific error is 'Paramter cannot be null. Paramater name: encoder'
any help would be much appreciated.