我的C#源码可以将图片转换成文本格式的图案,如下:
- using System;
- using System.Drawing;
- using System.IO;
- namespace BMP2ASCII
- {
- class Program
- {
- static void Main(string[] args)
- {
- char[] ascii = new char[] { '#', '#', '*','*','+','+','+',';',';',':',':',',',',','.','.',' ',' ' };
- Bitmap bmp = new Bitmap("C:\\panda.jfif");
- string txt = null;
-
- for (int y = 0; y < bmp.Height; y++)
- {
- for (int x = 0; x < bmp.Width; x++)
- {
- uint rgb = ((uint)bmp.GetPixel(x, y).ToArgb() & 0xFFFFFF) / 1048576;
- //Console.Write(ascii[rgb]);
- txt += ascii[rgb];
- }
- //Console.WriteLine();
- txt += "\n";
- }
- File.WriteAllText(@"C:\Users\khann\Desktop\panda.txt", txt);
- Console.ReadLine();
- }
- }
- }
复制代码特地来分享一下。
|