Get the color of the image using java -


how color of image icon.png using java

actually have servlet wll sending image using multipart file transfer, server should respond color of icon file, here image file has single color;

assuming have path image file:

color getimagecolor(file imagepath) {     bufferedimage image = imageio.read(imagepath);     int color = image.getrgb(0, 0);     (int r = 0; r < image.getheight(); r += 1) {         (int c = 0; c < image.getwidth(); c += 1) {             if (image.getrgb(c, r) != color) {                 throw new illegalargumentexception("image: " + imagepath + " not solid color.");             }         }     }      return new color(color); } 

this code assumes image have single color , pulls first pixel only.

the loop there make sure entire image 1 color. there many ways handle situation, of course.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -