使用ashx显示小图片
使用ashx显示小图片(不存在的小图)
ashx文件与.aspx文件类似,可以通过它来调用HttpHandler类,它免去了普通.aspx页面的控件解析以及页面处理的过程。.ashx文件适合产生供浏览器处理的、不需要回发处理的数据格式,例如用于生成动态图片、动态文本等内容。
<%@ WebHandler Language="C#" Class="showpic" %>
using System;
using System.Web;
using System.Drawing;
using System.IO;
public class showpic : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string pic = context.Request["pic"];
Bitmap bit = new Bitmap(context.Server.MapPath("~/tp/image_cp/" + pic));
//context.Server.MapPath("~/tp/image_cp/" + pic)是图片路径哦
//bit.Height
MemoryStream ms=new MemoryStream();
int newh=0;
int neww=0;
//
if (bit.Width < 150 && bit.Height < 150)
{
newh = bit.Height;
neww = bit.Width;
}
else
{
double pwidth = (double)bit.Width / 150;
double pheight = (double)bit.Height / 150;
if (pwidth > pheight)
{
neww = 150;
newh = Convert.ToInt32(bit.Height / pwidth);
}
else
{
newh = 150;
neww = Convert.ToInt32(bit.Width / pheight);
}
}
//生成小图
Bitmap newbit = new Bitmap(bit, neww, newh);
newbit.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
context.Response.ContentType = "image/jpeg";
context.Response.StatusCode = 200;
context.Response.BinaryWrite(ms.ToArray());
//context.Response.BinaryWrite(
}
public bool IsReusable {
get {
return false;
}
}
}
- Control Study->AdRotator广告控件显示自定义配置文件中广告以及与DataGrid控件结合使用显示图片(示例代码下载)
- 【转】结合ashx来在DataGrid中显示从数据库中读出的图片
- 【Vegas原创】访问owa,图片和js脚本不能正常显示和使用的解决方法
- Control Study->AdRotator广告控件显示自定义配置文件中广告以及与DataGrid控件结合使用显示图片(示例代码下载)
- 结合ashx来在DataGrid中显示从数据库中读出的图片
- 使用TCPMP解码显示JPEG图片WINCE5.0
- MFC上显示GIF图片(使用 GIF Animation Control控件)
- 使用asp.net将图片上传并存入SqlServer中,然后从SqlServer中读取并显示出来
- Control Study->AdRotator广告控件显示自定义配置文件中广告以及与DataGrid控件结合使用显示图片(示例代码下载)
- 结合ashx来在DataGrid中显示从数据库中读出的图片
- 使用PhotoShop分割图片并通过Html组合显示
- 图片上传生成缩略图,并使用JQuery实现鼠标移动到缩略图显示相应的大图的例子
- 在asp.net中自动合并小图片并使用css sprite显示出来
- Widget中使用ImageView显示图片的问题
- monotouch在使用uiwebview时加载本地html文件时的图片显示
- 使用 javascript 函数 完美控制页面图片显示大小 By shawl.qiu
- 使用控件显示图片
- 使用IPicture接口显示图片
- 使用ashx文件生成验证码图片
- 使用流对象保存和显示图片