Java_图片转字符
2024-10-09 07:10:34
把高达头像转换成字符[-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();
}
}
}
最新文章
- android r.styleable是什么或报错
- MySQL查询语句(select)详解(1)
- 【SSO单点系列】(1):CAS4.0 环境的搭建
- Notepad++的列编辑功能
- HTML中常用meta整理
- Unity3D脚本语言UnityScript初探
- JS中数组的操作
- ECMAScript整理笔记(持续更新....)
- H264码流解析及NALU
- 【Itext】7步制作Itext5页眉页脚pdf实现第几页共几页
- 阿里云ECS每天一件事D5:安装php5.4.34
- POJ 1207 3N+1 Problem
- webpack的学习准备工作
- 论文笔记:Auto-ReID: Searching for a Part-aware ConvNet for Person Re-Identification
- Struts2环境搭建和运用
- hashlib,hmac,subprocess,configparser,xlrd,xlwt,xml模块基本功能
- poj1852 Ants(思维)
- HTML 5 <;input>; list 属性
- Maven启动代理访问
- [BZOJ3693]圆桌会议[霍尔定理+线段树]