title: Quickest way to compare two BitmapImages to check if they are different in WPF
body: <p>What's the quickest way to compare 2 BitmapImage objects. One is in the Image Source property, and another I create in code.</p>
  
  <p>I can set the image source with the new bitmap image, but it causes flickering because it keeps setting the same image over and over.</p>
  
  <p>I'd like to only set the image if its pixels are different from the one in Image.Source.</p>
  
  <p>EDIT:</p>
  
  <p>AlbumArt is the Image in the view (following MVVM).</p>
  
  <p>Some code (running in the view code-behind):</p>
  
  <pre><code>Task.Factory.StartNew(() =&gt;
      {
          while (((App)Application.Current).Running)
          {
              Thread.Sleep(1000);
  
              Application.Current.Dispatcher.Invoke(new Action(() =&gt;
              {
                  if ((this.DataContext as AudioViewModel).CurrentDevice != null)
                  {
                      if ((((this.DataContext as AudioViewModel).CurrentDevice) as AUDIO).SupportsAlbumArt)
                      {
                          BitmapImage image = new BitmapImage();
                          image.BeginInit();
                          image.UriSource = new Uri((((this.DataContext as AudioViewModel).CurrentDevice) as AUDIO).AlbumArt);
                          image.CacheOption = BitmapCacheOption.None;
                          image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                          image.EndInit();
  
                          AlbumArt.Source = image;
                          ...
  </code></pre>