What is the easiest way to display an image from Byte[]?
<p>I have a structure containing an image in black and white:</p>

<pre><code>public class Img
{
    public int height;
    public int width;
    public byte[] matrix;
}
</code></pre>

<p>The values containing in matrix are 0 or 255.</p>

<p>What is the best way to display this image in a component using C# WPF?</p>

<p>I've try this :</p>

<p>XAML:</p>

<pre><code>&lt;Image Grid.Row="0"
       Stretch="Uniform"
       Source="{Binding Picture, Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"/&gt;
</code></pre>

<p>C#:</p>

<pre><code>public BitmapImage Picture
{
    get
    {
        return _picture;
    }
    private set
    {
        _picture = value;
        OnPropertyChanged("Picture");
    }
}

public void Generate()
{
    Img img = CreateImg();
    Picture = LoadImage(img.width, img.height, img.matrix);
}

private BitmapImage LoadImage(int w, int h, byte[] imageData)
{
    using (MemoryStream memory = new MemoryStream(imageData))
    {
        memory.Position = 0;
        BitmapImage bitmapimage = new BitmapImage();
        bitmapimage.BeginInit();
        bitmapimage.StreamSource = memory;
        bitmapimage.EndInit();
        return bitmapimage;
    }
}
</code></pre>

<p>But it doesn't work:</p>

<blockquote>
  <p>"Exception from HRESULT : 0x88982F50"</p>
</blockquote>