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

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

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

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

冥思苦想之下,给节目加了点部门特色,在 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 的样式还是太单调了,老老实实剪视频去了。

最新文章

  1. mybatis Oracle 批量插入,批量更新
  2. 浅谈WEB前后端分离
  3. AppDelegate动态加载StoryBoard
  4. ASP.NET4.5Web API及非同步程序开发系列(2)
  5. 生活life
  6. Monte Carlo方法简介(转载)
  7. STL Map的使用
  8. javaweb学习总结(二十四)——jsp传统标签开发
  9. [Hibernate] - Criteria Select
  10. vue通过判断写样式(v-bind)
  11. 08_rlCoachKin自主编译,调试
  12. Xcode断点的一些黑魔法
  13. Google推出iOS功能性UI测试框架EarlGrey
  14. nginx的配置服务器集群,负载均衡
  15. Java基础(4)-数组
  16. Andrew Ng机器学习课程笔记--汇总
  17. JAVA 的 Date、Calendar的常用用法
  18. 解决Eclipse中无法直接使用Base64Encoder的问题(转载)
  19. 2016-03-22 OneZero团队 Daily Scrum Meeting
  20. 【Java】-NO.13.Algorithm.1.Java Algorithm.1.001-【Java 常用算法手册 】-

热门文章

  1. spring boot + mybatis + mybatis逆向工程 --- 心得
  2. SpringCloud的Config应用
  3. 使用Swing的GUI编程
  4. PAT 乙级 1001. 害死人不偿命的(3n+1)猜想 (15)(C语言描述)
  5. Ubuntu 18.04 server安装+搭建Seacms v10.1网站
  6. vue学习18-过滤器
  7. gin中的query和postform用法
  8. Java语法专题1: 类的构造顺序
  9. Java 继承02
  10. .NET 20周年软件趋势随想