Convert System.Windows.Media.Imaging.BitmapImage to byte array
<p>I have the code below to convert byte array and resize it to specific height and weight:</p>

<pre><code>public static BitmapImage LoadImage(byte[] imageData, int nWidth, int nHeight)
        {
            if (imageData == null || imageData.Length == 0) return null;
            var image = new BitmapImage();
            using (var mem = new MemoryStream(imageData))
            {
                mem.Position = 0;
                image.BeginInit();
                image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
                image.DecodePixelWidth = nWidth;
                image.DecodePixelHeight = nHeight;
                image.CacheOption = BitmapCacheOption.OnLoad;
                image.UriSource = null;
                image.StreamSource = mem;
                image.EndInit();
            }
            image.Freeze();
            return image;
        }
</code></pre>

<p>How can I convert it back to byte array?</p>
