[译文]ASCII art with C#
ASCII art with C#<?xml:namespace prefix = o />
翻译说明:原文版权归作者所有
原文作者:Daniel Fisher (lennybacon)
原文地址:http://www.codeproject.com/aspnet/ascii_art_with_c_.asp
译 者:zitiger http://zitiger.cnblogs.com/
[by Paul Farry]
<?xml:namespace prefix = v />
Introduction (介绍)
Behind the scenes: I like C# and I like ASCII art. So I asked myself if somebody has written some image to ASCII application in C#. I Googled but found nothing. I did image manipulation stuff for my company and so I decided to build a basic image-to-ASCII conversion library in C#.
背景:我喜欢C#和ASCII 艺术,所以试图知道是不是已经有人使用C#写了把图像转换成ASCII的应用.我Google了一下,没有发现.在公司我从事图像处理素材,所以我决定写一个把图像转换成ASCII的基本类库.
You can see a running sample here.
你能在这里看到一个运行着的例子.(译者注:我没有能够打开这个页面.)
Step 1: The Upload Form. (第一步 上传表单)
To keep it quite simple, I just check the content type and let my library do the rest.
简单起见,我只检查了上传文件的类型,其他的就交给我的类库去完成了.
File1.PostedFile.ContentType=="image/jpg" ||
File1.PostedFile.ContentType=="image/jpeg" ||
File1.PostedFile.ContentType=="image/pjpeg" ||
File1.PostedFile.ContentType=="image/bmp")
{
Output.Text = "<xmp>" +
StaticDust.AsciiArt.ConvertImage(
File1.PostedFile.InputStream) +
"</xmp>";
}
else
{
Step 2: The Library(第二步 类库)
The first thing I do is of course load the image:
首先,当然是加载图片.
Bitmap _image =
new Bitmap(_img, new Size(_img.Width, _img.Height));
_img.Dispose();
Next I grayscale the image - you'll see later why.
接着我把图片灰度化-过会你就知道为什么要这么做了.
new Rectangle(0, 0, _image.Width, _image.Height);
ColorMatrix _matrix = new ColorMatrix();
_matrix[0,0] = 1/3f;
_matrix[0,1] = 1/3f;
_matrix[0,2] = 1/3f;
_matrix[1,0] = 1/3f;
_matrix[1,1] = 1/3f;
_matrix[1,2] = 1/3f;
_matrix[2,0] = 1/3f;
_matrix[2,1] = 1/3f;
_matrix[2,2] = 1/3f;
ImageAttributes _attributes =
new ImageAttributes();
_attributes.SetColorMatrix(_matrix);
Graphics gphGrey = Graphics.FromImage(_image);
gphGrey.DrawImage(_image,
bounds,
0,
0,
_image.Width,
_image.Height,
GraphicsUnit.Pixel,
_attributes);
gphGrey.Dispose();
O.K. Now, we get to the interesting part.
好了,现在我们就要进入最有意思的部分了.
{
int _startY = (h*10);
for(int w=0; w<_image.Width/5; w++)
{
int _startX = (w*5);
int _allBrightness = 0;
I loop through the image's pixels and because I don't want one ASCII character per pixel, I take one per 10/5. To let every pixel influence the resulting ASCII char, I loop them and calculate the brightness of the amount.
我对图片的像素进行循环,我不想一个ASCII字符代表一个像素,而是代表10/5个(像素).为了让每个
像素效果都能在最终结果的ASCII字符里有所体现,我对代表一个ASCII字符的一组像素进行循环,然后计算它们的亮度和.
(译者:把图片上的所有像素按一定的大小分成N小块,再求出每一小块内所有像素的亮度和.)
{
for(int x=0; x<10; x++)
{
int _cY = y + _startY;
int _cX = x + _startX;
try
{
Color _c = _image.GetPixel(_cX, _cY);
int _b = (int)(_c.GetBrightness() * 10);
_allBrightness = (_allBrightness + _b);
}
catch
{
_allBrightness = (_allBrightness + 10);
}
Finally, I append different ASCII characters based on the calculated amount:
最后,我根据计算出来的和把不同的ASCII字符组合起来.
if(_sb<25)
{
_asciiart.Append("#");
}
else if(_sb<30)
{
That's all
Thanks to The Code Project and Chris Maunder, newtelligence and greetings to all C# coders out there.
感谢Code Project , Chris Maunder 和 newtelligence,并向所有C#爱好者问好.
译者的理解:
1. 通过Web上传一张图片;
2. 把图片进行灰度化(变成黑白);
3. 把图片划分成N个小块,对每个小块的内像素的亮度进行求和;
4. 根据每个小块的亮度平均值来选择合适的ASCII字符进行组合;
5. 输出.
欢迎杭州的朋友加入杭州.net俱乐部http://zitiger.cnblogs.com/archive/2005/07/28/201584.html.
另:马上大四了,找个实习单位,个人简历http://zitiger.cnblogs.com/archive/2005/07/26/200648.html,限杭州.
转载于:https://www.cnblogs.com/zitiger/archive/2005/07/29/203083.html
[译文]ASCII art with C#相关推荐
- 一行命令堆出你的新垣结衣,不爆肝也能创作ASCII Art
点击上方"视学算法",选择加"星标"或"置顶" 重磅干货,第一时间送达 兴坤 发自 凹非寺 量子位 报道 | 公众号 QbitAI 万恶之源 ...
- linux切换图片的代码,cacaview – Linux终端下将图片转换ASCII Art代码图案
有时你可能需要终端输出许多图片,那么现在就让我们在Linux终端打开一个新窗口显示图片. cacaview – Linux终端下将图片转换ASCII Art代码图案的命令. Ubuntu下安装命令: ...
- html用转义字符画菱形,JavaScript生成字符画(ASCII Art)
今天玩一些新的东西,大家都没有看过这样的视频: 或者 这样的图片: 网上有很多生成这种图片/视频的工具,但是每个程序员都有一颗造轮子的心,我们当然要玩出自己的花样啦.老规矩,还是先讲原理,建议先用自己 ...
- asc码转换 linux_Linux终端下将图片转换ASCII Art代码图案
有时你可能需要终端输出许多图片,那么现在就让我们在Linux终端打开一个新窗口显示图片. cacaview - Linux终端下将图片转换ASCII Art代码图案的命令. Ubuntu下安装命令: ...
- php ascii art,ASCII art (简体中文)
翻译状态:本文是 ASCII art 的翻译.上次翻译日期:2020-07-10.如果英文版本有所更改,则您可以帮助同步翻译. 软件 Asciiquarium - ASCII 艺术中的水族馆/海洋动画 ...
- ascii art c语言,ASCII art (简体中文)
翻译状态:本文是 ASCII art 的翻译.上次翻译日期:2020-07-10.如果英文版本有所更改,则您可以帮助同步翻译. 软件 Asciiquarium - ASCII 艺术中的水族馆/海洋动画 ...
- JavaScript生成字符画(ASCII Art)
2019独角兽企业重金招聘Python工程师标准>>> 今天玩一些新的东西,大家都没有看过这样的视频: bad apple 字符版 或者 这样的图片: 网上有很多生成这种图片/视频的 ...
- ASCII Art Studio
http://baike.baidu.com/view/694294.htm 软件名称 ASCII Art Studio 软件平台 Win9X Win NT Win2000 WinME Win XP ...
- ASCII Art@字符画LOGO字符生成@Font Generator
文章目录 字符画简介 refs 其他相关在线工具: 小标字符 图片转ASCII 关于中文和尺寸设置 手滑图案转为字符图 字符画简介 这种用 ASCII 字符(如字母.数字.符号等)来形成图形的艺术形式 ...
最新文章
- jQuery 发送 AJAX 请求
- 面试必备:LinkedHashMap源码解析(JDK8)
- 数据类型_分享redis中除5种基础数据类型以外的高级数据类型
- .NET 5 部署在docker上运行
- 坐标转换 计算机图形学_计算机图形学的转换类型
- vs的form标签引起css走样问题
- 【SpringMVC】SpringMVC: @RequestBody 和@ResponseBody 注解详解 NoHandlerFoundException
- VS中常用的环境变量
- allshare cast安卓版下载_PanDownload 安卓手机版,解决百度网盘下载速度慢
- 数据库连接串的问题。(如果是集群数据库的话)
- 实战内容(13)- Invalid audio stream. Exactly one MP3 audio stream is required.
- java——Random种子
- 纳米结构的仿真和分析
- CodeChef 遇到 Language Rejected 怎么办
- 过上等生活,享下等情欲
- 有哪些手游的账号卖了值钱?
- 区块链软件开发公司谈区块链为什么被大众所接受
- TextView极细字体
- 力扣(LeetCode)799. 香槟塔(C++)
- 让管理员将所有服务器连接到一台显示器,信息技术基础模拟题