[英]Create dynamic banner with Image Handler
我想創建自己的動態橫幅,於是我開始制作圖片處理程序,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://本地主機: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);
}
}
將您的代碼更改為以下內容(不是寫入而是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.