Java获取图片颜色占比

更新时间:2023-06-08 22:35:58 阅读: 评论:0

Java获取图⽚颜⾊占⽐北师版
import Pair;
import HexUtil;
import Slf4j;
import ImageIO;
import BufferedImage;
import File;
import IOException;
import HashMap;
import LinkedHashMap;
import Map;
import Collectors;
@Slf4j
public class ImageColorUtil {
/**
* 获取占⽐最⾼的颜⾊及其占⽐
*
third>巫山云雨在线观看* @param file 图⽚⽂件
* @param num  返回颜⾊数量
小米截屏快捷键* @return <;颜⾊,<;数量,⽐例>>
白灼基围虾的做法*/
private static Map<String, Pair<Integer, Double>>colorRate(File file,int num){
Map<String, Pair<Integer, Double>> result =new HashMap<>();
int[] rgb =new int[3];
BufferedImage bi =null;
try{
bi = ad(file);
}catch(IOException e){
<("read_img_fail", e);
}
if(bi ==null){
return result;
}
int width = bi.getWidth();
int height = bi.getHeight();
int minx = bi.getMinX();
int miny = bi.getMinY();
int total = width * height;
for(int i = minx; i < width; i++){
for(int j = miny; j < height; j++){
int pixel = bi.getRGB(i, j);
rgb[0]=(pixel &0xff0000)>>16;
rgb[1]=(pixel &0xff00)>>8;
模特走秀服装
rgb[2]=(pixel &0xff);
String color = String.join("","#", Hex(rgb[0]), Hex(rgb[1]), Hex(rgb[2])).toUpperCa();
ainsKey(color)){
Pair<Integer, Double> numRate = (color);
result.put(color,new Pair<>(Key()+1,(Key()+1)*1.0/ total));
}el{
result.put(color,new Pair<>(1,0.0));
}
}鬼怪的主题曲
}
Set().stream()
.sorted(paringByValue((v1, v2)-> v2.getKey().Key()))).limit(num)
.Map(Map.Entry::getKey, Map.Entry::getValue,(v1, v2)-> v1, LinkedHashMap::new));
}
public static void main(String[] args){
File file =new adImg("isite./snapshot/09179782d12d69a87330778ea657c210"));        Map<String, Pair<Integer, Double>> stringPairMap =colorRate(file,10);
System.out.println(stringPairMap);
}
半盏屠苏犹未举}

本文发布于:2023-06-08 22:35:58,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/906133.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:截屏   返回   基围
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图