首页 > Web开发 > 详细

文字像素(.NET)

时间:2020-01-18 16:50:45      阅读:74      评论:0      收藏:0      [点我收藏+]

无图言*

技术分享图片

代码实现

新建一个控制台应用程序, 调整 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(width: 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, width: 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

文字像素(.NET)

原文:https://www.cnblogs.com/taadis/p/12209457.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!