Hi there,
Convert BitmapImage to byte array:
byte[] data;
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmapImage));
using(MemoryStream ms = new MemoryStream())
{
encoder.Save(ms);
data = ms.ToArray();
}
or
public byte[] imageToByte(System.Drawing.Image img)
{
MemoryStream objMS = new MemoryStream();
img.Save(objMS,System.Drawing.Imaging.ImageFormat.Gif);
return objMS.ToArray();
}
Convert byte array to BitmapImage:
BitmapImage GetImage( byte[] rawImageBytes )
{
BitmapImage imageSource = null;
try
{
using ( MemoryStream stream = new MemoryStream( rawImageBytes ) )
{
stream.Seek( 0, SeekOrigin.Begin );
BitmapImage b = new BitmapImage();
b.SetSource( stream );
imageSource = b;
}
}
catch ( System.Exception ex )
{
}
return imageSource;
}
Hope it helps.