我带了一台通用手提器。
在我的用户组合中,我有一个用户控制,希望能够利用这一类静态方法。 但是,我不能使用 as类或方法。 是否重新获得任何违约或登记?
ghx代码:
<%@ WebHandler Language="C#" Class="GetTileImage" %>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.IO;
using System.Net;
public class GetTileImage : IHttpHandler, IRequiresSessionState
{
const string c_key = "dzi";
public void ProcessRequest(HttpContext context)
{
//context.Response.Cache.SetMaxAge(TimeSpan.FromMinutes(60));
}
public bool IsReusable
{
get
{
return true;
}
}
public static Bitmap LoadImage(string imageUrl)
{
Dictionary<string, Bitmap> images = (Dictionary<string, Bitmap>)HttpContext.Current.Session[c_key];
if (images == null)
{
images = new Dictionary<string, Bitmap>();
HttpContext.Current.Session[c_key] = images;
}
Bitmap bmp = null;
if (!images.ContainsKey(imageUrl))
{
try
{
string url = imageUrl;
if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
url = HttpContext.Current.Server.MapPath(url); WebClient wc = new WebClient(); Stream fs = wc.OpenRead(url); bmp = new Bitmap(fs); fs.Close();
}
catch { return null; }
} images.Add(imageUrl, bmp); if (images.Count > 5)
{
Dictionary<string, Bitmap>.KeyCollection.Enumerator e = images.Keys.GetEnumerator();
e.MoveNext();
string key = e.Current;
images.Remove(key);
}
return bmp;
}
}
User Control where I am accessing this:
Bitmap bmp = GetTileImage.LoadImage("");
求助台