protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int cishu = Config.GetInt32SafeFromQueryString(this, "cishu", -1);
string FilePath = Request["FilePath"];
//定义图片流
Byte[] byteImg = null;
if (FilePath.Length > 0 && FilePath.Contains("tif"))
{
var imginfo = System.Drawing.Image.FromFile(FilePath);
MemoryStream msinfo = new MemoryStream();
//将文件保留到指定 流中
imginfo.Save(msinfo, System.Drawing.Imaging.ImageFormat.Bmp);
byteImg = msinfo.ToArray();
}
else
{
byteImg = FilePath == string.Empty ? new byte[0] : File.ReadAllBytes(FilePath);
}
获取最后一个 "\" 的索引
//int startindex = FilePath.LastIndexOf(@"\") + 1;
获取文件名称
//string FileName = FilePath.Substring(startindex, FilePath.Length - startindex);
Response.Clear();//这里能解决64位windows Server2008服务器和2003服务器下载要求输入密码的问题
//Response.ContentType = "image";
//Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
//Response.OutputStream.Write(byteImg, 0, byteImg.Length);
//Response.Flush();
//Response.End();
//ConvertTiff2Jpeg(FilePath, FilePath.Replace("tif","jpg"));
if (cishu != -1)
{
Stream stream = new MemoryStream(byteImg);
System.Drawing.Bitmap img = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(stream, false); //转换成Bitmap
if (cishu == 1)
{
//顺时针旋转90
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
}
else if (cishu == 2)
{
//顺时针旋转180
img.RotateFlip(RotateFlipType.Rotate180FlipNone);
}
else if (cishu == 3)
{
//顺时针旋转270
img.RotateFlip(RotateFlipType.Rotate270FlipNone);
}
else
{
//默认顺时针旋转90
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
}
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
Byte[] bytems = ms.ToArray();
Response.ContentType = "image/jpg";
Response.Buffer = false;
Response.BinaryWrite(bytems);//写入二进制流
Response.End();
}
else
{
Response.ContentType = "image/jpg";
Response.Buffer = false;
Response.BinaryWrite(byteImg);//写入二进制流
Response.End();
}
}
}