这不是要准备公司年会了嘛

每个部门抓壮丁,必须安排至少一个节目

想着上去唱首歌算了,被毙,没有部门特色

妈蛋,唱歌没特色,那隔壁在前线工作的部门要表演个啥,抄表?

冥思苦想之下,给节目加了点部门特色,在 Console 输出文字图形来报幕。

需求有了,现在就等实现。

不就是在 Console 输出点内容嘛,想当年在学校输出 9x9 乘法表的时候简直 6 的一批。

实操下来,妈蛋,没有规律,没有算法可言啊。

只能一点点去画?这要画到猴年马月。

继续冥思苦想,诶?识别图片每个像素点的颜色是不是可以?说干就干。

先准备一张白底黑字的图片

static void Main(string[] args)
{
using (Bitmap bmp = new Bitmap("文件地址"))
{
for (int i = 0; i < bmp.Height; i++)
{
for (int j = 0; j < bmp.Width; j++)
{
Color pixelColor = bmp.GetPixel(j, i);
if (IsBlack(pixelColor))
{
// 黑色
Console.Write("*");
}
else
{
// 白色
Console.Write(" ");
}
}
Thread.Sleep(5);
Console.Write("\n");
}
}
} static bool IsBlack(Color color)
{
return (color.R != 255 || color.G != 255 || color.B != 255);
}

代码就这么些代码,觉有有趣就分享出来一下。

再给大家分享一个可以修改 Console 字体大小的帮助类

public static class ConsoleHelper
{
private const int FixedWidthTrueType = 54;
private const int StandardOutputHandle = -11; [DllImport("kernel32.dll", SetLastError = true)]
internal static extern IntPtr GetStdHandle(int nStdHandle); [return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern bool SetCurrentConsoleFontEx(IntPtr hConsoleOutput, bool MaximumWindow, ref FontInfo ConsoleCurrentFontEx); [return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern bool GetCurrentConsoleFontEx(IntPtr hConsoleOutput, bool MaximumWindow, ref FontInfo ConsoleCurrentFontEx); private static readonly IntPtr ConsoleOutputHandle = GetStdHandle(StandardOutputHandle); [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct FontInfo
{
internal int cbSize;
internal int FontIndex;
internal short FontWidth;
public short FontSize;
public int FontFamily;
public int FontWeight;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
//[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.wc, SizeConst = 32)]
public string FontName;
} public static FontInfo[] SetCurrentFont(string font, short fontSize = 0)
{
FontInfo before = new FontInfo
{
cbSize = Marshal.SizeOf<FontInfo>()
}; if (GetCurrentConsoleFontEx(ConsoleOutputHandle, false, ref before))
{ FontInfo set = new FontInfo
{
cbSize = Marshal.SizeOf<FontInfo>(),
FontIndex = 0,
FontFamily = FixedWidthTrueType,
FontName = font,
FontWeight = 400,
FontSize = fontSize > 0 ? fontSize : before.FontSize
}; // Get some settings from current font.
if (!SetCurrentConsoleFontEx(ConsoleOutputHandle, false, ref set))
{
var ex = Marshal.GetLastWin32Error();
throw new System.ComponentModel.Win32Exception(ex);
} FontInfo after = new FontInfo
{
cbSize = Marshal.SizeOf<FontInfo>()
};
GetCurrentConsoleFontEx(ConsoleOutputHandle, false, ref after); return new[] { before, set, after };
}
else
{
var er = Marshal.GetLastWin32Error();
throw new System.ComponentModel.Win32Exception(er);
}
}
}
// 使用方式
ConsoleHelper.SetCurrentFont("Consolas", 50);

Console 的样式还是太单调了,老老实实剪视频去了。

通过C#在控制台输出各种图形文字的更多相关文章

  1. 【Python】在控制台输出不同颜色的文字

    今天调程序出了一个极为奇怪的问题,由于控制台输出挺多,就想把问题着重表示一下,具体即是在控制台输出红色文字. 于是在网上搜寻到了这篇:https://www.cnblogs.com/gongxr/p/ ...

  2. 利用ANSI转义序列在控制台输出彩色文字

    说明:无论什么语言,只要你的终端能够解释ANSI转义序列(大多数的类unix终端仿真器都能够解释ANSI转义序列,win32控制台则不支持),就能够使用ANSI转义序列输出颜色.这个功能看似鸡肋,但只 ...

  3. Java如何利用for循环在控制台输出正方形对角线图形

    1 /* 2 利用循环在控制台输出如下正方形对角线图形 3 * * * * * * * * * * * 4 * * * * 5 * * * * 6 * * * * 7 * * * * 8 * * * ...

  4. js控制台输出console

    介绍: js的console你可以在firefox的firedbug或者ie和google的f12调试模式下看到,这些主流浏览器的调试模式的控制可以输出一些信息,你的一些js代码测试可以直接在cons ...

  5. 前端不为人知的一面--前端冷知识集锦 前端已经被玩儿坏了!像console.log()可以向控制台输出图片

    前端已经被玩儿坏了!像console.log()可以向控制台输出图片等炫酷的玩意已经不是什么新闻了,像用||操作符给变量赋默认值也是人尽皆知的旧闻了,今天看到Quora上一个帖子,瞬间又GET了好多前 ...

  6. 自定义SpringBoot控制台输出的图案

    pringboot启动的时候,控制台输出的图案叫banner banner?啥玩意儿?相信有些人,一定是一脸懵逼... ——这个就不陌生了吧,这个是我们启动springboot的时候,控制台输出的.. ...

  7. python控制台输出颜色

    python_控制台输出带颜色的文字方法在开发项目过程中,为了方便调试代码,经常会向stdout中输出一些日志,默认的这些日志就直接显示在了终端中.而一般的应用服务器,第三方库,甚至服务器的一些通告也 ...

  8. .Net Core 控制台输出中文乱码

    Net Core 控制台输出中文乱码的解决方法: public static void Main(string[] args)         {             Console.Output ...

  9. Canopy测试IPython控制台输出

    Canopy测试IPython控制台输出

随机推荐

  1. Zuul网关 @EnableZuulProxy 和 @EnableZuulServer 的区别

    1. @EnableZuulProxy 2. @EnableZuulServer 3.解释 1)@EnableZuulProxy简单理解为@EnableZuulServer的增强版, 当Zuul与Eu ...

  2. 本地Java大数据环境基础配置(Maven)

    注:图片如果损坏,点击文章链接:https://www.toutiao.com/i6812623309138559500/ 创建项目 准备pom.xml文件配置(附在文档最后) 在下载jar过程中极其 ...

  3. 基于Apache Hudi + Flink的亿级数据入湖实践

    本次分享分为5个部分介绍Apache Hudi的应用与实践 实时数据落地需求演进 基于Spark+Hudi的实时数据落地应用实践 基于Flink自定义实时数据落地实践 基于Flink+Hudi的应用实 ...

  4. Parallel.For实现

    static class MyParallel { //4.0及以上用Task, Task的背后的实现也是使用了线程池线程 //static List<Task> tasks = new ...

  5. C# winform Visual Studio Installer打包教程,安装包

    //具体打包过程,参考下面网址 https://www.cnblogs.com/dongh/p/6868638.html VS 扩展和更新-联机 搜索 Microsoft Visual Studio ...

  6. 【解决了一个小问题】golang samara的kafka客户端中使用错误版本号导致初始化失败

    发现在如下代码中存储kafka生产者初始化失败: config.Version = sarama.V0_10_2_1 //V2_2_0_0 producer, err := sarama.NewSyn ...

  7. Cesium入门2 - Cesium环境搭建及第一个示例程序

    Cesium入门2 - Cesium环境搭建及第一个示例程序 Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ 验 ...

  8. Cesium入门1 - Cesium介绍

    Cesium入门1 - Cesium介绍 Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ Cesium简介 Ce ...

  9. MySQL表空间结构

    在Innodb中,我们可以指定一张表的数据是保存在独立表空间还是系统表空间,这个参数是:innodb_file_per_table 如果我们设置这个参数的值为0,那么一个表将使用系统表空间来保存表的数 ...

  10. Java安全之C3P0利用与分析

    Java安全之C3P0利用与分析 目录 Java安全之C3P0利用与分析 写在前面 C3P0 Gadget http base C3P0.getObject() 序列化 反序列化 Class.forN ...