在web页面中显示多页的tif文件
一、显示指定index页序号的tiff图片
1、通过页面显示
在显示页面里:<img src="showtif.aspx" border=0>
采用类似于验证码的显示方法
showtif.aspx的页面代码写成下面:(该页不带后台代码)
<%@ Page language="c#" %>
<%@ Import Namespace="test" %>
<% bind.showMulTif("img/aaa.tif",1);%>
方法showMulTif如下定义
/// <summary>
/// 显示多页tif图片
/// </summary>
/// <param name="fielname">文件名</param>
/// <param name="index">显示页码</param>
public static void showMulTif(string fielname,int index)
{
HttpContext context = HttpContext.Current;
string bgFilePath = context.Server.MapPath(fielname);
System.Drawing.Image imgObj = System.Drawing.Image.FromFile(bgFilePath);
//获得第index页的图片
Guid objGuid =(imgObj.FrameDimensionsList[0]);
System.Drawing.Imaging.FrameDimension objDimension =new System.Drawing.Imaging.FrameDimension(objGuid);
//总页数
int totFrame ;
totFrame=imgObj.GetFrameCount(objDimension);
if (index>totFrame)
index=totFrame;
if (index<1)
index=1;
imgObj.SelectActiveFrame(objDimension,index);
// 设置输出的MIME类型
context.Response.ContentType = "image/gif";
// 输出文件流到浏览器中
//
imgObj.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
// 释放资源
context.Response.Flush();
context.Response.End();
}
/// 显示多页tif图片
/// </summary>
/// <param name="fielname">文件名</param>
/// <param name="index">显示页码</param>
public static void showMulTif(string fielname,int index)
{
HttpContext context = HttpContext.Current;
string bgFilePath = context.Server.MapPath(fielname);
System.Drawing.Image imgObj = System.Drawing.Image.FromFile(bgFilePath);
//获得第index页的图片
Guid objGuid =(imgObj.FrameDimensionsList[0]);
System.Drawing.Imaging.FrameDimension objDimension =new System.Drawing.Imaging.FrameDimension(objGuid);
//总页数
int totFrame ;
totFrame=imgObj.GetFrameCount(objDimension);
if (index>totFrame)
index=totFrame;
if (index<1)
index=1;
imgObj.SelectActiveFrame(objDimension,index);
// 设置输出的MIME类型
context.Response.ContentType = "image/gif";
// 输出文件流到浏览器中
//
imgObj.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
// 释放资源
context.Response.Flush();
context.Response.End();
}
2、通过下载打开的方式,利用ioffice带的工具或图片查看器浏览
二、tif转换为jpg文件
将tif转换成多个jpge或者gif拉
public int SavePic(string fullPath,int index)
{
//使指定的页码在本图片的范围内
if(index < 0 || index > this.frameNumber)
{
index = 0;
}
//将指定的一页画到saveGif上,其中saveGif为指定的大小
Point ulCorner = new Point(0, 0);
Point urCorner = new Point(this.saveWidth,0);
Point llCorner = new Point(0, this.saveHeight);
Point[] destPara = {ulCorner, urCorner, llCorner};
saveGif= new Bitmap(this.saveWidth,this.saveHeight);
Graphics save = Graphics.FromImage(saveGif);
openTif.SelectActiveFrame(frameDime,index);
save.DrawImage(openTif,destPara);
save.Dispose();
save = null;
//将图片保存
saveGif.Save(fullPath,ImageFormat.Gif);
saveGif.Dispose();
saveGif = null;
return 1;
}
{
//使指定的页码在本图片的范围内
if(index < 0 || index > this.frameNumber)
{
index = 0;
}
//将指定的一页画到saveGif上,其中saveGif为指定的大小
Point ulCorner = new Point(0, 0);
Point urCorner = new Point(this.saveWidth,0);
Point llCorner = new Point(0, this.saveHeight);
Point[] destPara = {ulCorner, urCorner, llCorner};
saveGif= new Bitmap(this.saveWidth,this.saveHeight);
Graphics save = Graphics.FromImage(saveGif);
openTif.SelectActiveFrame(frameDime,index);
save.DrawImage(openTif,destPara);
save.Dispose();
save = null;
//将图片保存
saveGif.Save(fullPath,ImageFormat.Gif);
saveGif.Dispose();
saveGif = null;
return 1;
}