日期:2014-05-17  浏览次数:20745 次

C# 画图问题,没几分了,求大神看下。
请大神给分析下,代码功能如下,有一个文本,文本内容以00-09为主,每一个数字代表一个颜色,文本是按照图片宽、高写的,比如图片是640*480,那么文本每一行是1280个字符(因为代表颜色的是双位数),一共480行,下面的代码可以画出图来(颜色是乱设定的),现在可以实现画图功能,但是非常慢,求大神给优化下。
private void DrawImage(string s)
        {
            StringBuilder sb = new StringBuilder();
            string[] s1 = s.Replace("\r\n", "|").Split('|');
            int l, w;
            l = l4;
            w = a4;
            Bitmap bmp = new Bitmap(l, w);
            Graphics draw = Graphics.FromImage(bmp);
            draw.Clear(Color.Black);
            Color c = Color.FromArgb(255);
            Pen p = new Pen(c);
            p.Color = Color.FromArgb(255);
            for (int i = 0; i < w; i++)
            {
                for (int a = 0; a < l*2; a++)
                {
                    #region
                    switch (s1[i].Substring(a, 2))
                    {
                        case "00":
                            {
                                p.Color = Color.FromArgb(0, 255, 0);
                                draw.DrawRectangle(p, a/2, i, 1, 1);
                                a++;
                                break;
                            }