Is there a simple way to compare BufferedImage instances?

前端 未结 8 911
刺人心
刺人心 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:06

    You could write your own routine for comparison!

    int width;
    int height;
    boolean imagesEqual = true;
    
    if( image1.getWidth()  == ( width  = image2.getWidth() ) && 
        image1.getHeight() == ( height = image2.getHeight() ) ){
    
        for(int x = 0;imagesEqual == true && x < width; x++){
            for(int y = 0;imagesEqual == true && y < height; y++){
                if( image1.getRGB(x, y) != image2.getRGB(x, y) ){
                    imagesEqual = false;
                }
            }
        }
    }else{
        imagesEqual = false;
    }
    

    This would be one way!!!

提交回复
热议问题