I am trying to save jpeg image from buffer array of RGBA.
I tried this code
byte[] buffer = new byte[m_FrameProps.ImgSize];
Marshal.Copy(m_BM.BackBuffer, buffer, 0, m_FrameProps.ImgSize); //m_BM is WriteableBitmap
using (MemoryStream imgStream = new MemoryStream(buffer))
{
using (System.Drawing.Image image = System.Drawing.Image.FromStream(imgStream))
{
image.Save(m_WorkingDir + "1", ImageFormat.Jpeg);
}
}
But I am getting run-time error: "An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll
Additional information: Parameter is not valid."
I tried also to create bitmap and then to use JpegBitmapEncoder
Bitmap bitmap;
using (var ms = new MemoryStream(buffer))
{
bitmap = new Bitmap(ms);
}
But I am getting the same error.
I guess it is because the alpha.
How should I do it? Do I need to loop the values and copy without alpha?