图片查看器处理程序
来源:互联网 发布:瑞合信led软件下载 编辑:程序博客网 时间:2024/05/20 18:50
图片查看器处理程序是为了对请求的文件夹的内容进行筛选,选择图象并安排表格视图
程序实现分为:
1.从文件夹中检索图片文件,并收集文件信息;
2.将图片文件以设定的格式显示.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.IO;
/**//// <summary>
/// imagemaneger 的摘要说明
/// </summary>
//提取文件夹中的图象文件
public class imagemaneger:IHttpHandler
...{
public imagemaneger()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
//检索文件夹路径.并从文件夹中提取文件
private ArrayList images(string path)
...{
string[] imagetype =...{ "*.JPG", "*.png", "*.gif", "*.bmp" };
ArrayList image = new ArrayList();
//查询目录
DirectoryInfo di = new DirectoryInfo(path);
foreach (string type in imagetype)
...{
FileInfo[] files = di.GetFiles(type);
if (files.Length > 0)
...{
image.AddRange(files);
}
}
return image;
}
//从请求路径中找出检索文件路径
private string changeurlpath(HttpContext context)
...{
string path = context.Request.Path;
Char[] pathchar = path.ToCharArray();
for (int i = 0; i < pathchar.Length; i++)
...{
if (pathchar[i] == '/')
...{
pathchar[i]='/';
}
}
string nesstrings = new string(pathchar);
int index = nesstrings.IndexOf("pictureview.axd");
string newstring = "D:/mywebtest" + path.Remove(index);
return newstring;
}
//从请求连接读去图片管理信息
private picturinfo floatinfo(HttpContext context)
...{
picturinfo pictureinfo = new picturinfo();
string path = changeurlpath(context);
object p1 = context.Request.Params["width"];
object p2 = context.Request.Params["col"];
if (p1 != null)
...{
Int32.TryParse((string)p1, out pictureinfo.displaywidth);
}
if (p2 != null)
...{
Int32.TryParse((string)p2, out pictureinfo.collcount);
}
pictureinfo.floatname = path;
return pictureinfo;
}
/**//// <summary>
// 遍历文件夹中的图象文件,将其放在一指定的table中,并将table转化为字符串
/**//// </summary>
/// <param name="picture"></param>
/// <returns></returns>
string createooutput(picturinfo picture)
...{
ArrayList imagearraylist = images(picture.floatname);
Table t = new Table();
int index = 0;
bool moreimage = true;
while (moreimage)
...{
TableRow row = new TableRow();
t.Rows.Add(row);
for (int i = 0; i < picture.collcount;i++ )
...{
TableCell cell = new TableCell();
row.Cells.Add(cell);
Image image = new Image();
//获取文档案图象的文件信息
FileInfo fi = (FileInfo)imagearraylist[index];
image.Width = Unit.Pixel(picture.displaywidth);
image.ImageUrl =picture.floatname;
//为没图象加铆
HtmlAnchor a = new HtmlAnchor();
a.HRef = fi.Name;
a.Controls.Add(image);
cell.Controls.Add(a);
index++;
moreimage = (index < imagearraylist.Count);
if (!moreimage)
break;
}
}
string html=stringunit.controltohtmlstring(t);
return html;
}
IHttpHandler 成员#region IHttpHandler 成员
public bool IsReusable
...{
get ...{ return true; }
}
/**//// <summary>
/// 处理请求,并将图片按要求显示出来
/// </summary>
/// <param name="context"></param>
public void ProcessRequest(HttpContext context)
...{
picturinfo pitureinfo = floatinfo(context);
string html = createooutput(pitureinfo);
context.Response.Write("<html><head><title>");
context.Response.Write("Picture View");
context.Response.Write("</title></head><body>");
context.Response.Write(html);
context.Response.Write("</body></html>");
}
#endregion
}
public class picturinfo
...{
public int displaywidth;
public int collcount;
public string floatname;
public picturinfo()
...{
displaywidth = 200;
collcount = 3;
}
}
//注册HTTP处理程序
<httpHandlers>
<add verb="*" path="pictureview.axd" type="imagemaneger"/>
</httpHandlers>
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.IO;
/**//// <summary>
/// imagemaneger 的摘要说明
/// </summary>
//提取文件夹中的图象文件
public class imagemaneger:IHttpHandler
...{
public imagemaneger()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
//检索文件夹路径.并从文件夹中提取文件
private ArrayList images(string path)
...{
string[] imagetype =...{ "*.JPG", "*.png", "*.gif", "*.bmp" };
ArrayList image = new ArrayList();
//查询目录
DirectoryInfo di = new DirectoryInfo(path);
foreach (string type in imagetype)
...{
FileInfo[] files = di.GetFiles(type);
if (files.Length > 0)
...{
image.AddRange(files);
}
}
return image;
}
//从请求路径中找出检索文件路径
private string changeurlpath(HttpContext context)
...{
string path = context.Request.Path;
Char[] pathchar = path.ToCharArray();
for (int i = 0; i < pathchar.Length; i++)
...{
if (pathchar[i] == '/')
...{
pathchar[i]='/';
}
}
string nesstrings = new string(pathchar);
int index = nesstrings.IndexOf("pictureview.axd");
string newstring = "D:/mywebtest" + path.Remove(index);
return newstring;
}
//从请求连接读去图片管理信息
private picturinfo floatinfo(HttpContext context)
...{
picturinfo pictureinfo = new picturinfo();
string path = changeurlpath(context);
object p1 = context.Request.Params["width"];
object p2 = context.Request.Params["col"];
if (p1 != null)
...{
Int32.TryParse((string)p1, out pictureinfo.displaywidth);
}
if (p2 != null)
...{
Int32.TryParse((string)p2, out pictureinfo.collcount);
}
pictureinfo.floatname = path;
return pictureinfo;
}
/**//// <summary>
// 遍历文件夹中的图象文件,将其放在一指定的table中,并将table转化为字符串
/**//// </summary>
/// <param name="picture"></param>
/// <returns></returns>
string createooutput(picturinfo picture)
...{
ArrayList imagearraylist = images(picture.floatname);
Table t = new Table();
int index = 0;
bool moreimage = true;
while (moreimage)
...{
TableRow row = new TableRow();
t.Rows.Add(row);
for (int i = 0; i < picture.collcount;i++ )
...{
TableCell cell = new TableCell();
row.Cells.Add(cell);
Image image = new Image();
//获取文档案图象的文件信息
FileInfo fi = (FileInfo)imagearraylist[index];
image.Width = Unit.Pixel(picture.displaywidth);
image.ImageUrl =picture.floatname;
//为没图象加铆
HtmlAnchor a = new HtmlAnchor();
a.HRef = fi.Name;
a.Controls.Add(image);
cell.Controls.Add(a);
index++;
moreimage = (index < imagearraylist.Count);
if (!moreimage)
break;
}
}
string html=stringunit.controltohtmlstring(t);
return html;
}
IHttpHandler 成员#region IHttpHandler 成员
public bool IsReusable
...{
get ...{ return true; }
}
/**//// <summary>
/// 处理请求,并将图片按要求显示出来
/// </summary>
/// <param name="context"></param>
public void ProcessRequest(HttpContext context)
...{
picturinfo pitureinfo = floatinfo(context);
string html = createooutput(pitureinfo);
context.Response.Write("<html><head><title>");
context.Response.Write("Picture View");
context.Response.Write("</title></head><body>");
context.Response.Write(html);
context.Response.Write("</body></html>");
}
#endregion
}
public class picturinfo
...{
public int displaywidth;
public int collcount;
public string floatname;
public picturinfo()
...{
displaywidth = 200;
collcount = 3;
}
}
//注册HTTP处理程序
<httpHandlers>
<add verb="*" path="pictureview.axd" type="imagemaneger"/>
</httpHandlers>
- 图片查看器处理程序
- 安卓笔记之网络图片查看器小程序以及消息处理机制运用
- 图片处理程序
- ImageMagick 图片处理程序
- 简单图片查看器小程序源代码实现
- 调用系统图片查看器查看图片
- bootstrap+swiper 图片查看器 图片查看
- MagicWand图片处理程序安装
- 微信小程序中的图片处理
- 一般处理程序处理图片上传下载
- 【Html5+JS】简单的查看图片程序
- C#图片查看器
- C#图片查看器
- 图片查看器beta1
- Android图片查看器
- 图片查看器
- 图片查看器
- matlab图片查看器
- 关于MSSQLSERVER 中 TRUNCATE TABLE 和 DELETE 的区别
- 六 伪指令
- Java实现利用搜索引擎收集网址的程序
- 请不要做浮躁的人!
- C#中的命名规则与编码规范
- 图片查看器处理程序
- cmpp发送超长短信息
- Websphere编程之路 《MQ编程 For Delphi》 --MQ编程初探
- C#人民币转换
- 实战Java多线程编程之不提倡的方法
- 中华人民共和国民法通则
- EXCEl导入导出到SQL
- C++程序员经常问的11个问题
- 开源七大盈利模式