首页 新闻 赞助 找找看

关于C#Bitmap System.ArgumentException: 参数无效 问题

0
悬赏园豆:5 [已关闭问题] 关闭于 2012-05-25 20:42
<%@ WebHandler Language="C#" class="HttpHandler访问" %>

using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;

public class HttpHandler访问 : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "image/JPEG";
        
      string path = HttpContext.Current.Server.MapPath("1.jpg");//运行到这里出现异常
      using (Bitmap bitmap = new Bitmap(path))
        {
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.DrawString("IP:" + context.Request.UserHostAddress, new Font("黑体", 30), Brushes.Red, 0, 0
                );
            }
            bitmap.Save(context.Response.OutputStream, ImageFormat.Jpeg);
        }        
    }
}

求解
SEAZEG的主页 SEAZEG | 初学一级 | 园豆:199
提问于:2012-05-24 19:12
< >
分享
所有回答(2)
0

string path = HttpContext.Current.Server.MapPath("1.jpg");

这个运行异常?不应该的啊?你写成这样看:

string path = HttpContext.Current.Server.MapPath("~/1.jpg");

你那个写法默认对应为:

string path = HttpContext.Current.Server.MapPath("./1.jpg");

都不会有错的。

无之无 | 园豆:5095 (大侠五级) | 2012-05-24 19:32

还是不行啊.我直接往new Bitmap("c:/1.jpg")就没问题。 查过path中路径没问题,但放到MapPath中就出异常。。

支持(0) 反对(0) SEAZEG | 园豆:199 (初学一级) | 2012-05-24 19:37
0

终于解决了。还是路径问题。

Bitmap bitmap = new Bitmap("images/"+path)
SEAZEG | 园豆:199 (初学一级) | 2012-05-25 20:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册