public class DetermineTheColor {
/**
*
* @param imagePath 下载图片的路径
* @param fileTmpPath 临时目录 以/结尾
* @return 返回true是彩色图片 返回false是黑灰图片
* @throws Exception
*/
public static Boolean execote(String imagePath,String fileTmpPath) throws Exception {
//下载图片之后的名字
String fileName = String.format("%1$tY%1$tm%1$td%1$tH%1$tM%1$tS%1$tL",new Date())+Utils.randomNum(5) +".jpg";
//下载图片
downLoadFromUrl(imagePath,fileName,fileTmpPath);
BufferedImage src = ImageIO.read(new File(fileTmpPath+fileName));
int height = src.getHeight();
int width = src.getWidth();
int[] rgb = new int [4];
int o = 0;
for(int i =0;i<width;i++){
for(int j =0;j<height;j++){
int pixel = src.getRGB(i, j);
rgb[1] = (pixel & 0xff0000) >> 16;
rgb[2] = (pixel & 0xff00) >> 8;
rgb[3] = (pixel & 0xff);
//如果像素点不相等的数量超过50个 就判断为彩色图片
if(rgb[1] != rgb[2] && rgb[2] != rgb[3] && rgb[3] != rgb[1]){
o+=1;
if(o>=50){
return true;
}
}
}
}
return false;
}
/**
*
* @param imagePath 下载图片的路径
* @param fileTmpPath 临时目录 以/结尾
* @return 返回true是彩色图片 返回false是黑灰图片
* @throws Exception
*/
public static Boolean execote(String imagePath,String fileTmpPath) throws Exception {
//下载图片之后的名字
String fileName = String.format("%1$tY%1$tm%1$td%1$tH%1$tM%1$tS%1$tL",new Date())+Utils.randomNum(5) +".jpg";
//下载图片
downLoadFromUrl(imagePath,fileName,fileTmpPath);
BufferedImage src = ImageIO.read(new File(fileTmpPath+fileName));
int height = src.getHeight();
int width = src.getWidth();
int[] rgb = new int [4];
int o = 0;
for(int i =0;i<width;i++){
for(int j =0;j<height;j++){
int pixel = src.getRGB(i, j);
rgb[1] = (pixel & 0xff0000) >> 16;
rgb[2] = (pixel & 0xff00) >> 8;
rgb[3] = (pixel & 0xff);
//如果像素点不相等的数量超过50个 就判断为彩色图片
if(rgb[1] != rgb[2] && rgb[2] != rgb[3] && rgb[3] != rgb[1]){
o+=1;
if(o>=50){
return true;
}
}
}
}
return false;
}