ASCII Art

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 excited emotion icon \\(\\rightarrow\\) ヾ(≧∇≦*)ゝ.

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();
}

You can even make this program animated like this:

The End. \\(\\Box\\)

以上是关于ASCII Art的主要内容,如果未能解决你的问题,请参考以下文章

text Go Gopher ASCII Art

ASCII Art

通过 Python 把图片转换为 ASCII art,好玩!

如何将 ASCII Art 存储到批处理文件中的变量中?

如何使用 Java 或 Javascript 将 ASCII Art 解析为 HTML? [关闭]

一行命令堆出你的新垣结衣,不爆肝也能创作ASCII Art