• 文字像素(.NET)


    无图言*

    代码实现

    新建一个控制台应用程序, 调整 Program.cs 文件内容如下:

    using System;
    using System.Drawing;
    
    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.Title = "文字像素(.NET)";
                Console.WriteLine(value: "请输入任何文本,最好不要太长!");
                string str = Console.ReadLine();
    
                using (Bitmap bitmap = new Bitmap( 100, height: 12))
                {
                    using (Graphics graphics = Graphics.FromImage(image: bitmap))
                    {
                        graphics.Clear(color: Color.White);
                        graphics.DrawString(s: str, font: new Font(familyName: "宋体", emSize: 10), brush: Brushes.Black, x: 0, y: 0);
                        graphics.FillEllipse(brush: Brushes.White, x: 10, y: 10,  10, height: 10);
                    }
    
                    for (int y = 0; y < bitmap.Height; y++)
                    {
                        for (int x = 0; x < bitmap.Width; x++)
                        {
                            Console.Write(value: bitmap.GetPixel(x: x, y: y).ToArgb() == Color.White.ToArgb() ? " " : "*");
                        }
                        Console.WriteLine();
                    }
                }
                Console.ReadKey();
            }
        }
    }
    
    

    注意事项

    .NET Framework 中内置了 System.Drawing 库, 但是在 .NET Core 中因为某些原因没有内置, 需要通过 NuGet 下载 System.Drawing.Common

  • 相关阅读:
    六、mysql字段类型选择
    五、mysql存储引擎
    四、mysql内置函数
    三、mysql运算符
    二、mysql数据类型
    一、mysql使用入门
    拉链法解决Hash节点冲突问题
    CSS3样式
    CSS样式表
    HTML的表格、表单和框架
  • 原文地址:https://www.cnblogs.com/taadis/p/12209457.html
Copyright © 2020-2023  润新知