I found the following code on web to convert WriteableBitmap to byte array but this code does not work with Silverlight. Can someone please tell me what changes are needed to make it work with Silverlight.
byte[] ConvertBitmapToByteArray(WriteableBitmap bitmap)
{
WriteableBitmap bmp = bitmap;
using (Stream stream = bmp.PixelBuffer.AsStream())
{
MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
}
It gives the following error message:
'System.Windows.Media.Imaging.WriteableBitmap' does not contain a definition for 'PixelBuffer' and no extension method 'PixelBuffer' accepting a first argument of type 'System.Windows.Media.Imaging.WriteableBitmap' could be found (are you missing a using directive or an assembly reference?)