public void replaceImageColor(String file, Color srcColor, Color targetColor) throws IOException{
URL http;
if(file.trim().startsWith("https")){
http = new URL(file);
HttpsURLConnection conn = (HttpsURLConnection) http.openConnection();
conn.setRequestMethod("GET");
}else if(file.trim().startsWith("http")){
http = new URL(file);
HttpURLConnection conn = (HttpURLConnection) http.openConnection();
conn.setRequestMethod("GET");
}else{
http = new File(file).toURI().toURL();
}
BufferedImage bi = ImageIO.read(http.openStream()); for (int i = 0; i < bi.getWidth(); i++) {
for (int j = 0; j < bi.getHeight(); j++) {
System.out.println(bi.getRGB(i, j));
if(srcColor.getRGB()==bi.getRGB(i, j)){
System.out.println(i+","+j+" from:"+srcColor.getRGB()+"to"+targetColor.getRGB());
bi.setRGB(i, j, targetColor.getRGB());
}
}
}
Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName("png");
ImageWriter writer = it.next();
File f = new File("c://test02.png");
ImageOutputStream ios = ImageIO.createImageOutputStream(f);
writer.setOutput(ios);
writer.write(bi);
bi.flush();
ios.flush();
ios.close();
} public void createImage(int width, int height) throws IOException{
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D graphic = bi.createGraphics();
graphic.setColor(new Color(0.2f,0.3f,0.4f,0.4f));
graphic.fillRect(0, 0, width, height); for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
//result[i][j] = bi.getRGB(i, j) & 0xFFFFFF;
System.out.println(bi.getRGB(i, j));
// bi.setRGB(i, j, 0xFFFFFF);
}
} Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName("png");
ImageWriter writer = it.next();
File f = new File("c://test02.png");
ImageOutputStream ios = ImageIO.createImageOutputStream(f);
writer.setOutput(ios); writer.write(bi);
}

最新文章

  1. 在web浏览器上显示室内温度(nodeJs+arduino+socket.io)
  2. C#返回时间格式转换成 js 字符串
  3. ATPCS和AAPCS
  4. log4net 添加自定义日志到数据库
  5. 【UVA 11401】Triangle Counting
  6. HDOJ 2089 不要62
  7. 谈谈防止Ajax重复点击提交
  8. uva 1378 A Funny Stone Game (博弈-SG)
  9. win7下安装Ubuntukylin-14.04双系统
  10. [2017BUAA软工助教]第0次个人作业
  11. Udacity并行计算课程笔记-The GPU Hardware and Parallel Communication Patterns
  12. mac下更新自带的PHP版本到5.6
  13. (八十六)使用系统自带的分享框架Social.framework
  14. Maven&amp;&amp;Philosophy~
  15. 粘包-socketserver实现并发
  16. GitLab上传项目到新的分支
  17. vue.js及项目实战[笔记]— 02 vue.js基础
  18. java mail session使用Properties的clone方法
  19. 产品经理-visio
  20. openal支持的通道数和声道数

热门文章

  1. ajax向前台输出二维数组 并解析
  2. openstack的控制节点部署
  3. python爬取网站数据
  4. Python学习教程(learning Python)--1.2.3 Python格式化输出百分比
  5. 使用eclipse开发
  6. C 基于UDP实现一个简易的聊天室
  7. Oracle ClusterwarePRCT-1011 : Failed to run &quot;oifcfg&quot;.&amp;nb
  8. Android保存图片到系统图库
  9. Android编程: 界面组成、事件监听器
  10. Android实现KSOAP2访问WebService