ASCII Art

Conmajia, 2012
Updated on Feb. 18, 2018

What is ASCII art?

It‘s graphic symbols formed by ASCII characters instead of colorful pixels. ASCII art is an old technique when the network was not that developed as today. Net bandwidth was so limited and expensive those days, that people had to figure out some substitutions for images. Here is an example to show an excellent or excited emotion icon - ヾ(≧?≦*)ゝ.

In this article, I tried to use a brightness-to-character palette to build ASCII art from an pixel-based image.

The core code is less than 50 lines as below.

public static string Generate(Bitmap img, int rowSz, int colSz)
{
    StringBuilder sb
        = new StringBuilder(
        img.Width / colSz * img.Height / rowSz
        );
    FastBitmap fast
        = new FastBitmap(
        img
        );

    fast.Lock();
    for (int h = 0; h < img.Height / rowSz; h++)
    {
        int yoffset = h * rowSz;
        for (int w = 0; w < img.Width / colSz; w++)
        {
            int xoffset = w * colSz;
            int br = 0;

            for (int y = 0; y < 10; y++)
                for (int x = 0; x < 10; x++)
                    try
                    {
                        Color c = fast.GetPixel(
                            x + xoffset,
                            y + yoffset);
                        br =
                            br + (int)(c.GetBrightness() * 10);
                    }
                    catch
                        br += 10;
            br /= 10;
            if (br / 5 < charset.Length)
                sb.Append(
                    charset[br / 5]);
            else
                sb.Append(' ');
        }
        sb.AppendLine();
    }
    fast.Unlock();

    return sb.ToString();
}

Below is a preview:

You can even make this program animated like this:

\(\Box\)

原文地址:https://www.cnblogs.com/conmajia/p/ascii-art-v2.html

时间: 2025-01-14 16:40:37

ASCII Art的相关文章

ASCII 码对应表

Macron symbol ASCII CODE 238 : HTML entity : [ Home ][ español ] What is my IP address ? your public IP address is: 118.163.184.243 ASCII control characters 00NULL(Null character) 01SOH(Start of Header) 02STX(Start of Text) 03ETX(End of Text) 04EOT(E

UVA 1641 POJ 4022 ASCII Area

统计斜杠出现了奇数次还是偶数次 点击打开链接 Long time ago, most of PCs were equipped with video cards that worked only in text mode. If theprogrammer wanted to show a picture on a screen, he had to use pseudographics or ASCII art like this:^..^(OO)/ \()()In this problem

Linux/Unix 桌面趣事:文字模式下的 ASCII 艺术与注释绘画

boxes 命令不仅是一个文本过滤器,同时是一个很少人知道的有趣工具,它可以在输入的文本或者代码周围框上各种ASCII 艺术画.你可以用它快速创建邮件签名,或者在各种编程语言中留下评论块.这个命令可以在 vim 文本编辑器中使用,但是也可以在各种支持过滤器的文本编辑器中使用,同时也可以在命令行中单独使用. 任务: 安装 boxes 使用 apt-get 命令 在 Debian / Ubuntu Linux 中安装 boxes: $ sudo apt-get install boxes 输出示例:

『ENGLISH』

以A字母开头的词汇 英文 中文 abstract module 抽象模组 access 访问.存取 access control 存取控制 access control information 存取控制资讯 access mechanism 存取机制 access rights 存取权限 accessibility 无障碍性 accessibility information 无障碍网页资讯 accessibility problem 无障碍网页问题 accessible 无障碍的 access

(转)Linux下PS命令详解

(转)Linux下PS命令详解 整理自:http://blog.chinaunix.net/space.php?uid=20564848&do=blog&id=74654 要对系统中进程进行监测控制,查看状态,内存,CPU的使用情况,使用命令:/bin/ps (1) ps :是显示瞬间进程的状态,并不动态连续: (2) top:如果想对进程运行时间监控,应该用 top 命令: (3) kill 用于杀死进程或者给进程发送信号: (4) 查看文章最后的man手册,可以查看ps的每项输出的含义

Redis代码阅读之Hacking Strings

Hacking Strings The implementation of Redis strings is contained in sds.c ( sds stands for Simple Dynamic Strings ).The C structure sdshdr declared in sds.h represents a Redis string: struct sdshdr { long len; long free; char buf[]; }; The buf charac

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

bzoj:1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会

Description The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their finest gowns, complete with corsages and new shoes. They know that tonight they will each try to perform the Round Dance. Only cows can perform the

Ubuntu软件包管理命令全面集锦

说明:由于图形化界面方法(如Add/Remove... 和Synaptic Package Manageer)比较简单,所以这里主要总结在终端通过命令行方式进行的软件包安装.卸载和删除的方法. 一.Ubuntu中软件安装方法 1.APT方式 (1)普通安装:apt-get install softname1 softname2 …; (2)修复安装:apt-get -f install softname1 softname2... ;(-f Atemp to correct broken dep