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的更多相关文章
随机推荐
- 使用python来操作redis用法详解
1.redis连接 redis提供两个类Redis和StrictRedis用于实现Redis的命令,StrictRedis用于实现大部分官方的命令,并使用官方的语法和命令,Redis是StrictRe ...
- MySQL server has gone away错误的解决办法
在我们使用mysql导入大文件sql时可能会报MySQL server has gone away错误,该问题是max_allowed_packet配置的默认值设置太小,只需要相应调大该项的值之后再次 ...
- SQL ServerAlways Encrypted Data
SQL Server 提供了一个加密表上字段的功能, Encrypt Columns , 比如身份证号码,手机号码,银行账户等等敏感信息.
- 手写数字识别 ----卷积神经网络模型官方案例注释(基于Tensorflow,Python)
# 手写数字识别 ----卷积神经网络模型 import os import tensorflow as tf #部分注释来源于 # http://www.cnblogs.com/rgvb178/p/ ...
- 使用JumpServer管理你的服务器
本文介绍CentOS 7从安装jumpserver到简单使用jumpserver管理服务器. 1.Jumpserver介绍 Jumpserver是一款开源的开源的堡垒机,如下图是官网介绍. 官网地址: ...
- [数据结构] 用C语言模拟一个简单的队列程序
#include<stdio.h> #include <stdlib.h> #include<string.h> #include<math.h> // ...
- c++编辑器配置
notepad++ cmd /k cd /d "$(CURRENT_DIRECTORY)" & g++ "$(FILE_NAME)" -o " ...
- 953.Verifying an Alien Dictionary(Map)
In an alien language, surprisingly they also use english lowercase letters, but possibly in a differ ...
- Exp3 免杀原理与实践 20164302 王一帆
1 实践内容 1.1 正确使用msf编码器(0.5分),msfvenom生成如jar之类的其他文件(0.5分),veil-evasion(0.5分),加壳工具(0.5分),使用shellcode编程( ...
- 微信小程序开发---自定义组件
开发者可以将页面内的功能模块抽象成自定义组件,以便在不同的页面中重复使用:也可以将复杂的页面拆分成多个低耦合的模块,有助于代码维护.自定义组件在使用时与基础组件非常相似. 创建自定义组件 类似于页面, ...