//画图片
private void CreateImage(string checkCode)
{    
     System.Drawing.Bitmap image = new         System.Drawing.Bitmap(checkCode.Length * 12 + 10, 22);
            Graphics g = Graphics.FromImage(image);            //try
            //{
                //生成随机生成器 
                Random random = new Random();                //清空图片背景色 
                g.Clear(Color.White);                //画图片的背景噪音线 
                for (int i = 0; i < 25; i++)
                {
                    int x1 = random.Next(image.Width);
                    int x2 = random.Next(image.Width);
                    int y1 = random.Next(image.Height);
                    int y2 = random.Next(image.Height);                    g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
                }                Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
                System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
                g.DrawString(checkCode, font, brush, 2, 2);                //画图片的前景噪音点 
                for (int i = 0; i < 100; i++)
                {
                    int x = random.Next(image.Width);
                    int y = random.Next(image.Height);                    image.SetPixel(x, y, Color.FromArgb(random.Next()));
                }                //画图片的边框线 
                g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                
                //Response.ClearContent();
                //Response.ContentType = "image/Gif";
                //Response.BinaryWrite(ms.ToArray());
            //}
            //finally
            //{
            //    g.Dispose();
            //    image.Dispose();
            //}
         }---------------------------
问题,这是ASP.NET的代码,在WINFROM中运行的时候,由于没有 Response对象的,要怎么改一下呢?
//Response.ClearContent();
//Response.ContentType = "image/Gif";
//Response.BinaryWrite(ms.ToArray());

解决方案 »

  1.   

    你只要得到了System.IO.MemoryStream对象,直接把他转换成Image对象,放在winform的pictutebox中就可以了
      

  2.   

    你要什么样的效果?可以显示到pictureboxpicturebox1.image=image;
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 最新版本:20070212http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  3.   

    哦,错了
    在下面代码里面,你不是有一个image对象吗?直接放在winform的pictutebox中就可以了
    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
      

  4.   

    画图片的话要在某个控件上画,比如PictureBox或者Form,在它们的Paint事件中传Graphics给你的那个方法。
      

  5.   

    谢谢,问题解决
    picturebox1.image=image;
    我明白了,简单问题,一会儿Winform,一会儿ASP.NET,头都晕了