首页  软件  游戏  图书  电影  电视剧

请输入您要查询的软件:

 

软件 C#将图片转换为ASCii字符 V1.0 绿色免费版 
内容

C#将图片转换为ASCii字符是一款将图片转为ASCII字符画工具,看别人发出来好玩的图片上有这样的代码照片图,就在网上查了下源码,居然有C#的,写了个小程序。转出来的效果,个人感觉挺像的。

使用说明

长宽是设定 要替换成字符的像素块大小 越小 越精细。
输出的是文本文件,保存路径为D:\test.txt,开txt文件 如太大 把 txt字体设置成最小 就可以看到效果了。

代码说明

private void button1_Click(object sender, EventArgs e)

        {

            string str = null;

            //上传照片

            OpenFileDialog op = new OpenFileDialog();

            if (op.ShowDialog() == DialogResult.OK)

            {

                var image = File.ReadAllBytes(op.FileName);

                MemoryStream ms1 = new MemoryStream(image);

                Bitmap bm = (Bitmap)Image.FromStream(ms1);

                str = Generate.GenerateStr(bm, int.Parse(comboBox2.Text),

                    int.Parse(comboBox1.Text), int.Parse(comboBox3.Text));

            }

            this.btnSave_Click(str);

            textBox1.Text = "已生成,文件位置D:\\test.txt";

        }

        private void btnSave_Click(string s)

        {

            StreamWriter sw = File.AppendText(@"D:\\test.txt"); //保存到指定路径

            sw.Write(s);

            sw.Flush();

            sw.Close();

        }

        /// <summary>

        /// 生成string

        /// </summary>

        /// <param name="bitmap">照片</param>

        /// <param name="rowSize">行大小</param>

        /// <param name="colSize">列大小</param>

        /// <param name="type">模式</param>

        /// <returns></returns>

        public static string GenerateStr(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[] { ' ', '.', '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 + 1, 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();        }

标签 c#,图片,字符画,ASCII字符
缩略图
软件名称 C#将图片转换为ASCii字符 V1.0 绿色免费版
软件图标
软件大小 50KB
发布时间
软件平台
软件语言 简体中文
软件授权 免费软件
操作系统 Windows平台
系统类型
用户评分 4
软件版本
官方网站
官方网址
软件截图
软件总类 电脑游戏
软件大类 软件下载-图形图像-图像转换-图片转字符画
软件小类 图像转换
开发者
主办单位名称
ICP备案名
备案号
使用年龄
下载链接
攻略教程
详细介绍
操控设备
隐私政策
查看权限
敏感权限获取说明
软件类型 国产软件
安全警示 适度休息有益身心健康,请勿长期沉迷于使用电脑或刷手机。
随便看

 

传承兰台文化,共同保存历史记忆!兰台网收藏软件、游戏、图片、图书、电影、电视剧等互联网档案,是免费和可借阅文本、电影、音乐等档案的数字图书馆。

 

Copyright © 2004-2025 xlantai.com All Rights Reserved
更新时间:2025/5/10 20:09:47