[英]Create dynamic banner with Image Handler
I want to create my own dynamic banner, so I started to create an Image Handler, atm I have this code: 我想创建自己的动态横幅,于是我开始制作图片处理程序,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;
}
}
}
} }
But when I call "http:// localhost :12361/FaeriaImage.ashx" I only get this: http://abload.de/image.php?img=1deib0.jpg . 但是,当我称之为的“http://本地主机:12361 / FaeriaImage.ashx”我只得到这样的: http://abload.de/image.php?img=1deib0.jpg 。
And when I call it in my site with I get no image. 当我在自己的网站中调用它时,我没有图像。
Whats is my mistake here? 我这是怎么了?
I've used the handler and as far as I know you need to draw the image in the handler. 我使用过处理程序,据我所知您需要在处理程序中绘制图像。 This code might help you as it helped me.
此代码可能会对您有所帮助,因为它对我有帮助。 Try it out
试试看
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);
}
}
Change you code to the following (not write but WriteFile) 将您的代码更改为以下内容(不是写入而是WriteFile)
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg";
context.Response.WriteFile("~/Images/bg1.jpg");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.