您现在的位置是:网站首页> 软件下载软件下载

图片转换成ascii码字符画-C#将图片转换为ASCii字符下载V1.0绿色版-软件下载

2021-05-20 123人已围观

简介 图片转换成ascii码字符画-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();

        }

        ///

        /// 生成string

        ///

        /// 照片

        /// 行大小

        /// 列大小

        /// 模式

        ///

        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[] { '丶', '卜', '乙', '日', '瓦', '

下载资源

-六神源码网