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
Post a Comment