另外一个问题:
C#下将真彩图转256色图的问题:
http://community.csdn.net/Expert/topic/3527/3527909.xml?temp=.5745203

解决方案 »

  1.   

    我没学过美术,不知道颜色间的关系,无法很好的表现颜色的深浅,所以转的效果不是很好:1、定义一些必要的对象
    Image image = Image.FromFile(fileName);
    Bitmap b = new Bitmap(image);
    stirng s = "";2、根据像素的颜色对图片进行转换
    for(int i = 0; i < b.Height; i+=3)
    {
        for(int j = 0; j < b.Width; j+=1)
        {
            Color c = b.GetPixel(j, i);   // 取得每个像素的颜色
            // 这里是对像素颜色的判断
            // 这里应该是个颜色范围的判断,但问题是我不知道范围该怎么取
            // 所以我只能用单一的颜色简单的判断一下了
            // 根据对颜色的判断返回一个与颜色匹配的字符
            if(c.ToArgb() == 0) s += " ";  // 像素是否为透明色
            else if(c.ToArgb() == Color.White.ToArgb()) s += " "; // 像素是否为白色
            else if(c.ToArgb() == Color.Black.ToArgb()) s += "$"; //像素是否为黑色
            else s += "*";
            // 循环一下系统消息队列
            Application.DoEvents();
        }
        s += "\n";  // 换行
    }3、将转换的字符串用 DrawString() 绘制到一个新建的 Image 上
    // 取得一个 Graphics 对象
    Graphics g = Graphics.FromImage(b);
    // 返回转换后的字符串所占的 2D Size
    SizeF sf = g.MeasureString(s, this.Font);
    // 新建一个 Bitmap 对象, 对象的大小由 字符串的 2D Size 决定
    Bitmap b1 = new Bitmap((int)sf.Width, (int)sf.Height);
    // 由新建的 B1 返回一个 Graphics 对象
    g = Graphics.FromImage(b1);
    // DrawString()
    g.DrawString(s, this.Font, Brushes.Black, 0.0f, 00.0f);
    // 释放 Graphics 占用的资源
    g.Dispose();4、显示图像
    PictureBox box = new PictureBox();
    box.Location = new Point(0, 0);
    box.SizeMode = PictureBoxSizeMode.AutoSize;
    box.Image = b1;
    this.AutoScroll = true;
    this.Controls.Add(box);