图片转ascii样式
来源:互联网 发布:外汇指标软件 编辑:程序博客网 时间:2024/04/27 23:55
public void createAsciiPic(String path) {
final String base = “@#&$%*o!;.”;// 字符串由复杂到简单
try {
/* 写入Txt文件 */
File writename = new File(“D:\output.txt”); // 相对路径,如果没有则要建立一个新的output.txt文件
writename.createNewFile(); // 创建新文件
BufferedWriter out = new BufferedWriter(new FileWriter(writename,true));
//String path=”D:\timg.jpg”;
final BufferedImage image = ImageIO.read(new File(path));
for (int y = 0; y < image.getHeight(); y += 2) {
for (int x = 0; x < image.getWidth(); x++) {
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)));
out.write(index >= base.length() ? ” ” : String.valueOf(base.charAt(index)));
//out.write(“1223”);
}
System.out.println();
out.write(“\r\n”);
}
out.flush(); // 把缓存区内容压入文件
out.close(); // 最后记得关闭文件
} catch (final IOException e) {
e.printStackTrace();
}
}
/**
* test
*
* @param args
*/
public static void main( String[] args) {
PictureToAscii pictureToAscii=new PictureToAscii();
pictureToAscii.createAsciiPic(“D:\qs.jpg”);
}
- 图片转ascii样式
- 图片转ascii
- Python 图片转ASCII码
- ASCII图片
- java实现图片转ascii字符画
- 图片样式,辅助类样式
- 图片ascii化的方法
- 上传图片的样式
- CSS3 图片样式
- JS 改变图片样式
- 新浪新闻图片样式
- 上传图片的样式
- UIBarButtonSystemItem的样式图片
- CSS图片样式
- retina 图片样式
- 图片BlendMode 样式
- 改变图片样式
- UIBarButtonSystemItem 样式 和 图片
- 瑞博PM9000GTA 系统漏气故障分析与处理方法
- 迅雷9屏蔽所有游览器和网站相应
- 关于tomcat服务器启动过慢问题的解决
- 3DSlicer3:模块管理(一)颜色、DCM、数据、模型、注释
- RGB转到LAB颜色空间,matlab和opencv内嵌函数使用的区别
- 图片转ascii样式
- 瓜皮机器学习——用java对ID3算法进行实现
- 删除指定路径下指定格式的文件
- Vegas Pro 14破解版震撼来袭!!!
- UDFs — User-Defined Functions
- C++加载PNG图片
- 小问题可能存在大问题,希望大神帮忙解答。Spark本地运行模式中单线程与多线程问题之setMaster("local")可以运行,但是设置成setMaster("local[3]")或setMaste
- Vue.js学习笔记:v-no绑定事件
- vue.js报错 [Vue warn]: Cannot find element: #app