| 发表于: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()); |
|
|
|
|