当前位置:编程学习 > C#/ASP.NET >>

AjaxPro.net中的服务器端Ajax方法中不能使用 GDI+ 创建图片吗?

在Ajax方法中加入下面的代码,方法返回字符串时在客户端收到null值,页面引入了以下名字空间:
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

Ajax方法也用了如下特征修饰:
[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]     



       // 创建验证码
        //建立位图对象
        Bitmap newBitmap = new Bitmap(36, 16, PixelFormat.Format32bppArgb);

        //根据上面创建的位图对象创建绘图面
        Graphics g = Graphics.FromImage(newBitmap);

        //以指定的颜色填充矩形区
        g.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, 36, 16));

        //创建字体对象
        Font textFont = new Font("Times New Roman", 10);

        //创建RectangleF结构指定一个区域
        RectangleF rectangle = new RectangleF(0, 0, 36, 16);

        //创建随机数对象
        Random rd = new Random();

        //取得随机数
        int validationNo = 0;
        validationNo = 1000 + rd.Next(8999);

        //使用指定的颜色填充上面RectangleF结构指定的矩形区域
        g.FillRectangle(new SolidBrush(Color.GreenYellow), rectangle);

        //创建验证图片中的杂点
        int colorIndex;
        Color[] colors = { Color.SaddleBrown, Color.Red, Color.GreenYellow, Color.Blue };
        Point[] points = new Point[2];
        Pen myPen = new Pen(Color.White);

        for (int i = 0; i < 2; ++i)
        {
            for (int j = 0; j < 2; ++j)
            {
                points[j].X = rd.Next(1, 35);
                points[j].Y = rd.Next(1, 15);
            }

            colorIndex = rd.Next(4);
            myPen.Color = colors[colorIndex];
            g.DrawCurve(myPen, points);
        }
        //结束创建验证图片中的杂点

        //在上面填充的矩形区域中填充上面生成的随机数
        g.DrawString(validationNo.ToString(), textFont, new SolidBrush(Color.Blue), 2, 1);
        //把创建的位图保存到指定的路径
        newBitmap.Save(HttpContext.Current.Server.MapPath("ValitionNoImg") + "\\VaImg.gif", ImageFormat.Gif);
        // 结束创建验证码 --------------------编程问答-------------------- 高手指点下啊…… --------------------编程问答-------------------- 怎么就没人顶我呀?  --------------------编程问答-------------------- 靠!还没有人顶啊……
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,