title: Is there a simple way to compare BufferedImage instances?
body: <p>I am working on part of a Java application that takes an image as a byte array, reads it into a <code>java.awt.image.BufferedImage</code> instance and passes it to a third-party library for processing.</p>
  
  <p>For a unit test, I want to take an image (from a file on disk) and assert that it is equal to the same image that has been processed by the code.</p>
  
  <ul>
  <li>My <strong>expected</strong> <code>BufferedImage</code> is read from a PNG file on disk using <code>ImageIO.read(URL)</code>.</li>
  <li>My <strong>test</strong> code reads the same file into a <code>BufferedImage</code> and writes that to a byte array as PNG to provide to the system under test.</li>
  </ul>
  
  <p>When the system under test writes the byte array to a new <code>BufferedImage</code> I want to assert that the two images are equal in a meaningful way. Using <code>equals()</code> (inherited from <code>Object</code>) doesn’t work (of course). Comparing <code>BufferedImage.toString()</code> values also doesn’t work because the output string includes object reference information.</p>
  
  <p>Does anybody know any shortcuts? I would prefer not to bring in a third-party library for a single unit test in a small part of a large application.</p>