title: How to bind an Image control to Image that save in Database in VarBinary type
body: <p>I want to bind an image that save in varbinary type in database in XAML.How I can do that?</p>
  
  <p>for example Picture field in northwind DataBase.</p>
  
  <p>thanks</p>
  
  <p><strong>EDIT 1:)</strong></p>
  
  <p>I write this codes for convert Image field (Picture field in Categories table in Northwind DataBase) but every time I get Exception:</p>
  
  <pre><code>class ImageConverter : IValueConverter
  {
      object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          if (value == null) { return null; }
  
          var image = (System.Drawing.Image)value;
          var bitmap = new System.Windows.Media.Imaging.BitmapImage();
          bitmap.BeginInit();
          MemoryStream memoryStream = new MemoryStream();
          image.Save(memoryStream, ImageFormat.Bmp);
          memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
          bitmap.StreamSource = memoryStream;
          bitmap.EndInit();
          return bitmap;
  
      }
  
      object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          throw new Exception("The method or operation is not implemented.");
      }
  }
  </code></pre>
  
  <p>And :</p>
  
  <pre><code>class ImageConverter : IValueConverter
  {
      object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          if (value != null &amp;&amp; value is byte[])
          {
              byte[] bytes = value as byte[];
              MemoryStream stream = new MemoryStream(bytes);
              BitmapImage image = new BitmapImage();
              image.BeginInit();
              image.StreamSource = stream;
              image.EndInit();
              return image;
          }
          return null;
      }
  
      object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          throw new Exception("The method or operation is not implemented.");
      }
  }
  </code></pre>
  
  <p>and the exception:</p>
  
  <pre><code>Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception.
  </code></pre>