zoukankan      html  css  js  c++  java
  • 文字像素(.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),  Brushes.Black, x: 0, y: 0);
                        graphics.FillEllipse( 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

  • 相关阅读:
    python排序
    JavaMail转发邮件
    Java发送邮件Demo
    字符编码
    常用的python内建函数
    mysql-python安装
    ubuntu安装flash
    grep简介
    【java中的static关键字】
    【java中的final关键字】
  • 原文地址:https://www.cnblogs.com/taadis/p/12209457.html
Copyright © 2011-2022 走看看