private string _imagePath;
private HttpRequest Request;
private HttpResponse Response;
private HttpServerUtility Server;
public string ImagePath
{
get { return this._imagePath; }
set { this._imagePath = value; }
}
public bool IsReusable
{
get
{
return false;
}
}
public void ProcessRequest(HttpContext context)
{
this.Server = context.Server;
this.Response = context.Response;
this.Request = context.Request;
this.RequestImage();
}
private void RequestImage()
{
string evento = this.Request.QueryString["evento"];
int imageHeight = Convert.ToInt32(this.Request.QueryString["h"]);
int imageWidth = Convert.ToInt32(this.Request.QueryString["w"]);
if ((imageHeight <= 0) && (imageWidth <= 0))
{
imageWidth = 140;
imageHeight = 110;
}
string Album = "";
Album = PhotoManager.GetRandomPhoto(Convert.ToInt32(this.Request.QueryString["AlbumID"]));
if (Album == String.Empty)
{
this.ImagePath = this.Server.HtmlDecode("~/eventos/nofotos.gif");
}
else
{
this.ImagePath = this.Server.HtmlDecode("~/eventos/" + Album);
}
this.Response.ContentType = this.ResponseType(this.ImagePath);
string imagePath = GetImagePath(this.Request.RawUrl);
Image thumbImage = null;
Bitmap drawImage = null;
thumbImage = Image.FromFile(HttpContext.Current.Server.MapPath(this.ImagePath));
try
{
if (imageHeight > 0 && imageWidth > 0)
{
drawImage = new Bitmap(thumbImage);
thumbImage = this.Resize(new Bitmap(drawImage), imageHeight, imageWidth);
drawImage.Dispose();
}
else
{
thumbImage = new Bitmap(thumbImage);
}
thumbImage.Save(this.Response.OutputStream, this.ImageType(this.ImagePath));
}
catch { }
finally
{
thumbImage.Dispose();
}
}
public static string GetImagePath(string rawUrl)
{
return rawUrl.Replace("&", "_").Replace("?", "_").Replace("/", "_").Replace("=", "_").Replace(".", "_");
}
private Bitmap Resize(Bitmap image, int height, int width)
{
Bitmap bmImage = new Bitmap(width, height);
Graphics gpImage = Graphics.FromImage(bmImage);
gpImage.CompositingQuality = CompositingQuality.GammaCorrected;
gpImage.InterpolationMode = InterpolationMode.HighQualityBicubic;
gpImage.SmoothingMode = SmoothingMode.AntiAlias;
gpImage.DrawImage(image, 0, 0, width, height);
gpImage.Dispose();
return bmImage;
}
private ImageFormat ImageType(string image_path)
{
switch (Path.GetExtension(image_path).ToLower())
{
case ".bmp":
return ImageFormat.Bmp;
case ".gif":
return ImageFormat.Gif;
case ".jpg":
return ImageFormat.Jpeg;
case ".png":
return ImageFormat.Png;
case ".tiff":
return ImageFormat.Tiff;
}
return null;
}
private string ResponseType(string image_path)
{
switch (Path.GetExtension(image_path).ToLower())
{
case ".bmp":
return "Image/bmp";
case ".gif":
return "Image/gif";
case ".jpg":
return "Image/jpeg";
case ".png":
return "Image/png";
case ".tiff":
return "Image/tiff";
}
return null;
} well these is my code so if you see anything or anyone sees anything wrong please tell me... :D