Created
March 5, 2014 21:36
-
-
Save betandr/9377142 to your computer and use it in GitHub Desktop.
Java: Get color from a solid image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Color getImageColor(File imagePath) { | |
BufferedImage image = ImageIO.read(imagePath); | |
int color = image.getRGB(0, 0); | |
for (int r = 0; r < image.getHeight(); r += 1) { | |
for (int c = 0; c < image.getWidth(); c += 1) { | |
if (image.getRGB(c, r) != color) { | |
throw new IllegalArgumentException("Image: " + imagePath + " is not a solid color."); | |
} | |
} | |
} | |
return new Color(color); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment