先上html代码
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="GjDetailInfo.aspx.cs" Inherits="CN.Web.GjDetailInfo" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<link href="../resource/sit.css" rel="stylesheet" type="text/css" /> <script language="javascript" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="7" style="height: 19px">
综合查询>>干警信息查询>>详细信息查询</td>
<td style="width: 18%; height: 19px">
</td>
<td style="width: 17%; height: 19px">
</td>
<td style="width: 5%; height: 19px">
<img border="0" height="23" src="../resource/images/sit/help.gif" width="59" /></td>
</tr>
<tr>
<td colspan="7" style="height: 21px">
</td>
<td style="width: 18%; height: 21px">
</td>
<td style="width: 17%; height: 21px">
</td>
<td style="width: 5%; height: 21px">
</td>
</tr>
</table>
<asp:Panel ID="pnlDetail" runat="server" Width="100%" Height="300px">
<table border="1" cellpadding="0" cellspacing="0" style="width: 100%; height: 250px;"
id="TABLE1" onclick="return TABLE1_onclick()">
<tr>
<td rowspan="7" style="width: 10%">
</td>
<td style="width: 15%">
</td>
<td style="width: 25%">
</td>
<td style="width: 15%">
</td>
<td rowspan="5" style="width: 15%">
</td>
<td rowspan="7" style="width: 10%">
</td>
</tr>
<tr style="color: #000000">
<td style="width: 15%">
<asp:Label ID="Lbemp_id" runat="server" Text="编 号:" Width="115px"></asp:Label></td>
<td style="width: 25%">
<asp:TextBox ID="txtemp_id" runat="server" Width="130px"></asp:TextBox></td>
<td style="width: 15%">
<asp:Label ID="Label1" runat="server" Text="照 片:" Width="115px"></asp:Label></td>
</tr>
<tr style="color: #000000">
<td style="width: 15%">
<asp:Label ID="lbemp_jhao" runat="server" Text="警 号:" Width="115px"></asp:Label></td>
<td style="width: 25%">
<asp:TextBox ID="txtemp_jhao" runat="server" Width="130px"></asp:TextBox></td>
<td style="width: 15%">
</td>
</tr>
<tr>
<td style="width: 15%">
<asp:Label ID="lbemp_name" runat="server" Text="姓 名:" Width="115px"></asp:Label></td>
<td style="width: 25%">
<asp:TextBox ID="txtemp_name" runat="server" onfocus="setday(this)" Width="130px"></asp:TextBox></td>
<td style="width: 15%">
</td>
</tr>
<tr>
<td style="width: 15%">
<asp:Label ID="lbdep_name" runat="server" Text="部门名称:" Width="115px"></asp:Label></td>
<td style="width: 25%">
<asp:TextBox ID="txtdep_name" runat="server" Width="130px"></asp:TextBox></td>
<td style="width: 15%">
</td>
</tr>
<tr>
<td style="width: 15%">
<asp:Label ID="lbemp_zhwu" runat="server" Text="职 务:" Width="115px"></asp:Label></td>
<td style="width: 25%">
<asp:TextBox ID="txtemp_zhwu" runat="server" Width="130px"></asp:TextBox></td>
<td style="width: 15%">
<asp:Label ID="Label2" runat="server" Text="开始时间:" Width="115px"></asp:Label></td>
<td style="width: 15%">
<asp:TextBox ID="txtemp_starttime" runat="server" onfocus="setday(this)" Width="130px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 15%; height: 26px;">
<asp:Label ID="lbemp_status" runat="server" Text="状 态:" Width="115px"></asp:Label></td>
<td style="width: 25%; height: 26px;">
<asp:TextBox ID="txtemp_status" runat="server" onfocus="setday(this)" Width="130px"></asp:TextBox></td>
<td style="width: 15%; height: 26px;">
<asp:Label ID="lbemp_endtime" runat="server" Text="结束时间:" Width="115px"></asp:Label></td>
<td style="width: 15%; height: 26px">
<asp:TextBox ID="txtemp_endtime" runat="server" onfocus="setday(this)" Width="130px"></asp:TextBox></td>
</tr>
</table>
</asp:Panel>
<asp:Image ID="imgPhoto" runat="server" Height="540px" Width="540px" /></div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="GjDetailInfo.aspx.cs" Inherits="CN.Web.GjDetailInfo" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<link href="../resource/sit.css" rel="stylesheet" type="text/css" /> <script language="javascript" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="7" style="height: 19px">
综合查询>>干警信息查询>>详细信息查询</td>
<td style="width: 18%; height: 19px">
</td>
<td style="width: 17%; height: 19px">
</td>
<td style="width: 5%; height: 19px">
<img border="0" height="23" src="../resource/images/sit/help.gif" width="59" /></td>
</tr>
<tr>
<td colspan="7" style="height: 21px">
</td>
<td style="width: 18%; height: 21px">
</td>
<td style="width: 17%; height: 21px">
</td>
<td style="width: 5%; height: 21px">
</td>
</tr>
</table>
<asp:Panel ID="pnlDetail" runat="server" Width="100%" Height="300px">
<table border="1" cellpadding="0" cellspacing="0" style="width: 100%; height: 250px;"
id="TABLE1" onclick="return TABLE1_onclick()">
<tr>
<td rowspan="7" style="width: 10%">
</td>
<td style="width: 15%">
</td>
<td style="width: 25%">
</td>
<td style="width: 15%">
</td>
<td rowspan="5" style="width: 15%">
</td>
<td rowspan="7" style="width: 10%">
</td>
</tr>
<tr style="color: #000000">
<td style="width: 15%">
<asp:Label ID="Lbemp_id" runat="server" Text="编 号:" Width="115px"></asp:Label></td>
<td style="width: 25%">
<asp:TextBox ID="txtemp_id" runat="server" Width="130px"></asp:TextBox></td>
<td style="width: 15%">
<asp:Label ID="Label1" runat="server" Text="照 片:" Width="115px"></asp:Label></td>
</tr>
<tr style="color: #000000">
<td style="width: 15%">
<asp:Label ID="lbemp_jhao" runat="server" Text="警 号:" Width="115px"></asp:Label></td>
<td style="width: 25%">
<asp:TextBox ID="txtemp_jhao" runat="server" Width="130px"></asp:TextBox></td>
<td style="width: 15%">
</td>
</tr>
<tr>
<td style="width: 15%">
<asp:Label ID="lbemp_name" runat="server" Text="姓 名:" Width="115px"></asp:Label></td>
<td style="width: 25%">
<asp:TextBox ID="txtemp_name" runat="server" onfocus="setday(this)" Width="130px"></asp:TextBox></td>
<td style="width: 15%">
</td>
</tr>
<tr>
<td style="width: 15%">
<asp:Label ID="lbdep_name" runat="server" Text="部门名称:" Width="115px"></asp:Label></td>
<td style="width: 25%">
<asp:TextBox ID="txtdep_name" runat="server" Width="130px"></asp:TextBox></td>
<td style="width: 15%">
</td>
</tr>
<tr>
<td style="width: 15%">
<asp:Label ID="lbemp_zhwu" runat="server" Text="职 务:" Width="115px"></asp:Label></td>
<td style="width: 25%">
<asp:TextBox ID="txtemp_zhwu" runat="server" Width="130px"></asp:TextBox></td>
<td style="width: 15%">
<asp:Label ID="Label2" runat="server" Text="开始时间:" Width="115px"></asp:Label></td>
<td style="width: 15%">
<asp:TextBox ID="txtemp_starttime" runat="server" onfocus="setday(this)" Width="130px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 15%; height: 26px;">
<asp:Label ID="lbemp_status" runat="server" Text="状 态:" Width="115px"></asp:Label></td>
<td style="width: 25%; height: 26px;">
<asp:TextBox ID="txtemp_status" runat="server" onfocus="setday(this)" Width="130px"></asp:TextBox></td>
<td style="width: 15%; height: 26px;">
<asp:Label ID="lbemp_endtime" runat="server" Text="结束时间:" Width="115px"></asp:Label></td>
<td style="width: 15%; height: 26px">
<asp:TextBox ID="txtemp_endtime" runat="server" onfocus="setday(this)" Width="130px"></asp:TextBox></td>
</tr>
</table>
</asp:Panel>
<asp:Image ID="imgPhoto" runat="server" Height="540px" Width="540px" /></div>
</form>
</body>
</html>
using System.Data;
using System.Configuration;
using System.Collections;
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.Data.SqlClient;
using System.IO;
using myLib;namespace CN.Web
{
public partial class GjDetailInfo : System.Web.UI.Page
{
string id, jhao;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.txtemp_jhao.Text = Session["emp_jhao"].ToString();
this.txtemp_id.Text = Session["emp_id"].ToString();
this.txtemp_name.Text = Session["emp_name"].ToString();
this.txtemp_status.Text = Session["emp_status"].ToString();
this.txtemp_zhwu.Text = Session["emp_zhwu"].ToString();
this.txtemp_starttime.Text = Session["emp_starttime"].ToString();
this.txtemp_endtime.Text = Session["emp_endtime"].ToString();
this.txtdep_name.Text = Session["Depname"].ToString();
//this.Image1.ImageUrl= ;
id = this.txtemp_id.Text.Trim();
jhao = this.txtemp_jhao.Text.Trim();
SqlConn();
SetReadOnly(pnlDetail);
}
}
//获得二进制文件的方法
protected void SqlConn()
{
this.imgPhoto.Height = 100;
this.imgPhoto.Width = 80;
string aidSelect = "select emp_sjk_photo from emp_photo where emp_id = '" + id + "'";
DataTable fileTable = new DataTable();
fileTable = DbAccess.GetDS(aidSelect).Tables[0];//DbAccess.GetDS执行数据库公用方法
if (fileTable.Rows.Count == 0)
{
Response.Write("<script>alert('没有照片!')</script>");
return;
}
byte[] photo = (byte[])fileTable.Rows[0][0];
this.Response.BinaryWrite(photo);
string strPath = "~/photo/" + jhao + ".jpg";
string x_strPath = "~/photo/" + "x_" + jhao + ".jpg";
string strPhotoPath = Server.MapPath(strPath);
string strPhotoPath_s = Server.MapPath(x_strPath);// 服务器端缩略图路径
MakeThumbnail(strPhotoPath, strPhotoPath_s, 130, 130, "Cut"); //保存图片文件
BinaryWriter bw = new BinaryWriter(File.Open(strPhotoPath, FileMode.OpenOrCreate));
bw.Write(photo);
bw.Close();
this.imgPhoto.ImageUrl = strPhotoPath_s;
}
/**/
/// <summary>
/// 生成缩略图
/// </summary>
/// <param name="originalImagePath">源图路径(物理路径)</param>
/// <param name="thumbnailPath">缩略图路径(物理路径)</param>
/// <param name="width">缩略图宽度</param>
/// <param name="height">缩略图高度</param>
/// <param name="mode">生成缩略图的方式</param>
public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)
{
System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath); int towidth = width;
int toheight = height; int x = 0;
int y = 0;
int ow = originalImage.Width;
int oh = originalImage.Height; switch (mode)
{
case "HW"://指定高宽缩放(可能变形)
break;
case "W"://指定宽,高按比例
toheight = originalImage.Height * width / originalImage.Width;
break;
case "H"://指定高,宽按比例
towidth = originalImage.Width * height / originalImage.Height;
break;
case "Cut"://指定高宽裁减(不变形)
if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
{
oh = originalImage.Height;
ow = originalImage.Height * towidth / toheight;
y = 0;
x = (originalImage.Width - ow) / 2;
}
else
{
ow = originalImage.Width;
oh = originalImage.Width * height / towidth;
x = 0;
y = (originalImage.Height - oh) / 2;
}
break;
default:
break;
} //新建一个bmp图片
System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight); //新建一个画板
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //清空画布并以透明背景色填充
g.Clear(System.Drawing.Color.Transparent); //在指定位置并且按指定大小绘制原图片的指定部分
g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight),
new System.Drawing.Rectangle(x, y, ow, oh),
System.Drawing.GraphicsUnit.Pixel); try
{
//以jpg格式保存缩略图
bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (System.Exception e)
{
throw e;
}
finally
{
originalImage.Dispose();
bitmap.Dispose();
g.Dispose();
}
}
//设置panel为只读
public void SetReadOnly(Panel panel)//这里要把TextBox所在的面板对象传进来
{
foreach (Control control in panel.Controls)
{
try
{
((TextBox)control).Enabled = false;
}
catch (Exception ex)
{ continue; }
}
}
}
}
等比例缩放图片
<script language="JavaScript">
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
} }
}onload="javascript:DrawImage1(this)">