Is there a simple way to compare BufferedImage instances?

前端 未结 8 910
刺人心
刺人心 2020-12-05 19:01

I am working on part of a Java application that takes an image as a byte array, reads it into a java.awt.image.BufferedImage instance and passes it to a third-p

8条回答
  •  眼角桃花
    2020-12-05 19:24

    You can write that image via imageio through an OutputStream to a byte[]. In my code, it looks more or less like this:

    byte[] encodeJpegLossless(BufferedImage img){...using imageio...}
    ...
    Assert.assertTrue(Arrays.equals(encodeJpegLossless(img1)
                                   ,encodeJpegLossless(img2)
                                   )
                     );
    

提交回复
热议问题