public static byte[] BitmapImageToByteArray(System.Windows.Controls.Image img) { byte[] ImgTemp; System.Windows.Media.Imaging.BitmapImage bitmapImage = new System.Windows.Media.Imaging.BitmapImage(); bitmapImage = ((System.Windows.Media.Imaging.BitmapImage)img.Source); System.Windows.Media.Imaging.JpegBitmapEncoder encoder = new System.Windows.Media.Imaging.JpegBitmapEncoder(); encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmapImage)); using (MemoryStream ms = new MemoryStream()) { encoder.Save(ms); ImgTemp = ms.ToArray(); } return ImgTemp; }