使用图像处理程序创建动态横幅



我想创建自己的动态横幅,所以我开始创建一个图像处理程序,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。

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

我在这里犯了什么错误?

我已经使用了处理程序,据我所知,您需要在处理程序中绘制图像。这段代码可能会帮助你,因为它帮助了我。试试吧

 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);
   }
 }

将代码更改为以下内容(不是写入而是写入文件)

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

最新更新