您的位置:程序门 -> .net技术 -> c#



asp.net的验证码源代码在winform中运行的一点小问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


asp.net的验证码源代码在winform中运行的一点小问题[已结贴,结贴人:yumanqing]
发表于:2007-03-27 10:41:47 楼主
//画图片
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());
发表于:2007-03-27 10:47:331楼 得分:5
你只要得到了system.io.memorystream对象,直接把他转换成image对象,放在winform的pictutebox中就可以了
发表于:2007-03-27 10:49:112楼 得分:5
你要什么样的效果?可以显示到picturebox

picturebox1.image=image;
   
*****************************************************************************
欢迎使用csdn论坛专用阅读器   :   csdn   reader(附全部源代码)  

最新版本:20070212

http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
发表于:2007-03-27 10:49:363楼 得分:0
哦,错了
在下面代码里面,你不是有一个image对象吗?直接放在winform的pictutebox中就可以了


system.io.memorystream   ms   =   new   system.io.memorystream();
                                image.save(ms,   system.drawing.imaging.imageformat.gif);

发表于:2007-03-27 10:50:424楼 得分:5
画图片的话要在某个控件上画,比如picturebox或者form,在它们的paint事件中传graphics给你的那个方法。
发表于:2007-03-27 10:55:085楼 得分:5
paint事件.楼上正解.
发表于:2007-03-27 11:10:216楼 得分:0
谢谢,问题解决
picturebox1.image=image;
我明白了,简单问题,一会儿winform,一会儿asp.net,头都晕了


快速检索

最新资讯
热门点击