0

我想创建自己的动态横幅,所以我开始创建一个图像处理程序,atm 我有这个代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Faeria
{
/// <summary>
/// Summary description for FaeriaImage
/// </summary>
public class FaeriaImage : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "image/jpeg";
        context.Response.Write("~/Images/bg1.jpg");
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

}

但是当我调用“http://localhost:12361/FaeriaImage.ashx”时,我只会得到这个:http ://abload.de/image.php?img=1deib0.jpg 。

当我在我的网站上调用它时,我没有得到任何图像。

我的错误是什么?

4

2 回答 2

1

我已经使用了处理程序,据我所知,您需要在处理程序中绘制图像。该代码可能对您有所帮助,因为它对我有所帮助。试试看

 using (Bitmap image = new Bitmap(context.Server.MapPath("~/Images/bg1.jpg")))
 {
   using(MemoryStream ms = new MemoryStream())
   {
      image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
      ms.WriteTo(context.Response.OutputStream);
   }
 }
于 2013-10-29T11:51:06.393 回答
0

将您的代码更改为以下内容(不是写入,而是 WriteFile)

public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "image/jpeg";
    context.Response.WriteFile("~/Images/bg1.jpg");
}
于 2013-10-29T12:33:12.177 回答