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

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

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

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

冥思苦想之下,给节目加了点部门特色,在 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. Pytest_Hook钩子函数总结(14)

    前言 pytest 的钩子函数有很多,通过钩子函数的学习可以了解到pytest在执行用例的每个阶段做什么事情,也方便后续对pytest二次开发学习.详细文档可以查看pytest官方文档https:// ...

  2. js 多层 元素叠起来避免误触的解决方法

    添加一层 元素,将点击事件设为 onClick="event.cancelBubble = true" 这样就能将两个可触发事件的元素给隔开

  3. antd中的form表单 initialValue导致数据不更新问题

    初步理解 : initialValue就是所谓的defaultValue,只会在第一次赋值的时候改变,却又有一些不同,因为 initialValue又会因其他改动而改变. 然而当获取的数据重新上来要渲 ...

  4. Echart可视化学习集合

    一.基本介绍:ECharts是一款基于JavaScript的数据可视化图表库,提供直观,生动,可交互,可个性化定制的数据可视化图表.ECharts最初由百度团队开源,并于2018年初捐赠给Apache ...

  5. 一文搞懂Flink Window机制

    Windows是处理无线数据流的核心,它将流分割成有限大小的桶(buckets),并在其上执行各种计算. 窗口化的Flink程序的结构通常如下,有分组流(keyed streams)和无分组流(non ...

  6. kafka学习笔记(四)kafka的日志模块

    概述 日志段及其相关代码是 Kafka 服务器源码中最为重要的组件代码之一.你可能会非常关心,在 Kafka 中,消息是如何被保存和组织在一起的.毕竟,不管是学习任何消息引擎,弄明白消息建模方式都是首 ...

  7. Keil MDK STM32系列(五) 使用STM32CubeMX创建项目基础结构

    Keil MDK STM32系列 Keil MDK STM32系列(一) 基于标准外设库SPL的STM32F103开发 Keil MDK STM32系列(二) 基于标准外设库SPL的STM32F401 ...

  8. Android官方文档翻译 十 2.3Styling the Action Bar

    Styling the Action Bar 设计菜单栏的样式 This lesson teaches you to 这节课教给你 Use an Android Theme 使用一个Android主题 ...

  9. Solon Web 开发,一、开始

    Solon Web 开发 一.开始 二.开发知识准备 三.打包与运行 四.请求上下文 五.数据访问.事务与缓存应用 六.过滤器.处理.拦截器 七.视图模板与Mvc注解 八.校验.及定制与扩展 九.跨域 ...

  10. 【记录一个问题】macos下lldb调试opencv的一个程序,出现“failed to load objfile for”错误,并且无法调试进入opencv的函数

    opencv编译使用了Debug版本,打开了BUILD_WITH_DEBUG_INFO=ON选项. 发现问题后,我又在CMAKE_CXX_FLAGS_DEBUG中设置为 -g -ggdb3,在CMAK ...