BitmapToASCii
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace PicToASCii
{
public static class ASCiiHelper
{
public static string Generate(Bitmap bitmap, int rowSize, int colSize, int type)
{
StringBuilder result = new StringBuilder();
char[] charset = { ' ', '.', ',', ':', ';', 'i', '1', 'r', 's', '5', '3', 'A', 'H', '9', '8', '&', '@', '#' };
if (type == 1)
{
//charset = new char[] { '8', '9', '6', '4', '3', '5', '7', '0', '2', '1', '.',' ' };
charset = new char[] { ' ', '.', '1', '2', '0', '7', '5', '3', '4', '6', '9', '8' };
}
else if (type == 2)
{
charset = new char[] { '丶', '卜', '乙', '日', '瓦', '車', '馬', '龠', '齱', '龖' };
}
int bitmapH = bitmap.Height;
int bitmapW = bitmap.Width;
for (int h = 0; h < bitmapH / rowSize; h++)
{
int offsetY = h * rowSize;
for (int w = 0; w < bitmapW / colSize; w++)
{
int offsetX = w * colSize;
float averBright = 0;
for (int j = 0; j < rowSize; j++)
{
for (int i = 0; i < colSize; i++)
{
try
{
Color color = bitmap.GetPixel(offsetX + i, offsetY + j);
averBright += color.GetBrightness();
}
catch (ArgumentOutOfRangeException)
{
averBright += 0;
}
}
}
averBright /= (rowSize * colSize);
int index = (int)(averBright * charset.Length);
if (index == charset.Length)
index--;
result.Append(charset[charset.Length - 1 - index]);
}
result.Append("\r\n");
}
return result.ToString();
}
}
}
BitmapToASCii的更多相关文章
随机推荐
- 咸鱼入门到放弃10--javaweb的两种开发模式
(本篇是之前方法的综合使用,新东西不多,其中也涉及三层架构的问题.此处直接引用了大佬blog:https://www.cnblogs.com/xdp-gacl/p/3908610.html) SUN公 ...
- spring boot 入门之 helloworld
第一步:创建一个普通的maven项目 第二步:配置springboot基础依赖配置(即配置pom和启动类) POM配置 <project xmlns="http://maven.apa ...
- 如何编写高效的jQuery代码(转载)
jQuery的编写原则: 一.不要过度使用jQuery 1. jQuery速度再快,也无法与原生的javascript方法相比,而且建立的jQuery对象包含的信息量很庞大.所以有原生方法可以使用的场 ...
- 结队第一次 plus
作业描述 作业所属课程:软件工程1916|W(福州大学) 作业要求:结对第一次-原型设计 结对学号:221600328 221600106 作业目标:尝试结对合作,使用NABCD模型,会分析用户需求, ...
- 印象笔记 MAC安装使用旧版本
印象笔记终于支持markdown了,赞! 第一个beta版用起来非常不错.提示更新安装新版本后保存markdown一直提示 "Note content is invalid.",无 ...
- sqlzoo:5
展示世界的總人口. SELECT sum(population) FROM world 列出所有的洲份, 每個只有一次. select distinct(continent) from world 找 ...
- KMP模板实现
看了出题知识点才发现自己连KMP都没有好好的理解,甚至一共就打过一次板子=-= 于是照着之前的课件学了一学...发现没怎么弄懂qwq 我太弱啦! 找了一篇自认为全网最好的介绍 觉得写得很棒 字符串匹配 ...
- Hive 本地调试方法
关键词:hive, debug 本地调试(local debug) Hive 可分为 exec (hive-exec,主要对应源码里的ql目录) 和 metastore 两部分,其中exec对外有两种 ...
- [AtCoder3856]Ice Rink Game - 模拟
Problem Statement An adult game master and N children are playing a game on an ice rink. The game co ...
- [Educational Round 17][Codeforces 762F. Tree nesting]
题目连接:678F - Lena and Queries 题目大意:给出两个树\(S,T\),问\(S\)中有多少连通子图与\(T\)同构.\(|S|\leq 1000,|T|\leq 12\) 题解 ...