把高达头像转换成字符[-V-]

调节双循环里y与x的增量改变字符输出的细节、高和长

 public class ImgToStr {
public static void main(String args []){
//图片路径
ImgToStr.createAsciiPic("D:\\StrLogo\\GUTy6x2.png");
} public static void createAsciiPic(final String path) {
//final String base = "@#&$%*o!;.";// 字符串由复杂到简单
final String base = "/lVXvi*!;.'";
try {
final BufferedImage image = ImageIO.read(new File(path));
System.out.println("W:"+image.getWidth()+" H:"+image.getHeight());
for (int y = 0; y < image.getHeight(); y += 6) {
for (int x = 0; x < image.getWidth(); x+= 2) {
final int pixel = image.getRGB(x, y);
final int r = (pixel & 0xff0000) >> 16, g = (pixel & 0xff00) >> 8, b = pixel & 0xff;
final float gray = 0.299f * r + 0.578f * g + 0.114f * b;
final int index = Math.round(gray * (base.length() + 1) / 255);
System.out.print(index >= base.length() ? " " : String.valueOf(base.charAt(index)));
}
System.out.println();
}
} catch (final IOException e) {
e.printStackTrace();
}
}
}

最新文章

  1. android r.styleable是什么或报错
  2. MySQL查询语句(select)详解(1)
  3. 【SSO单点系列】(1):CAS4.0 环境的搭建
  4. Notepad++的列编辑功能
  5. HTML中常用meta整理
  6. Unity3D脚本语言UnityScript初探
  7. JS中数组的操作
  8. ECMAScript整理笔记(持续更新....)
  9. H264码流解析及NALU
  10. 【Itext】7步制作Itext5页眉页脚pdf实现第几页共几页
  11. 阿里云ECS每天一件事D5:安装php5.4.34
  12. POJ 1207 3N+1 Problem
  13. webpack的学习准备工作
  14. 论文笔记:Auto-ReID: Searching for a Part-aware ConvNet for Person Re-Identification
  15. Struts2环境搭建和运用
  16. hashlib,hmac,subprocess,configparser,xlrd,xlwt,xml模块基本功能
  17. poj1852 Ants(思维)
  18. HTML 5 &lt;input&gt; list 属性
  19. Maven启动代理访问
  20. [BZOJ3693]圆桌会议[霍尔定理+线段树]

热门文章

  1. poj3764字典树路径最大异或和
  2. 带你学够浪:Go语言基础系列 - 8分钟学基础语法
  3. JAVA自定义数据类型用法
  4. 在树莓派里搭建 Lighttpd 服务器
  5. linux高级管理第十四章--kvm虚拟化
  6. JavaScript之倔强的字符串
  7. (七)剩余DAO代码
  8. python requests用于测试
  9. 伪静态%{REQUEST_FILENAME} !-f 和!-d用法
  10. ElementUi 全选功能实现