1
/// <summary>
2
/// 经过处理获取所略图
3
/// </summary>
4
/// <param name="ms"></param>
5
/// <param name="height"></param>
6
/// <returns></returns>
7
private byte[] LessonPicAutoWidth(MemoryStream ms, int height)
8
{
9
byte[] ChagedByte;
10
System.Drawing.Image OriginalImage = System.Drawing.Image.FromStream(ms, true);
11
System.Drawing.Bitmap OriginalPic, NewPic;
12
OriginalPic = new System.Drawing.Bitmap(OriginalImage);
13
int Width = height * OriginalPic.Width / OriginalPic.Height;
14![](/Images/OutliningIndicators/InBlock.gif)
15
if (Width > 280)
16
{
17
Width = 280;
18
}
19
NewPic = new Bitmap(OriginalPic, Width, height);
20
MemoryStream Newms = new MemoryStream();
21
NewPic.Save(Newms, System.Drawing.Imaging.ImageFormat.Jpeg);
22
ChagedByte = Newms.GetBuffer();
23
OriginalPic.Dispose();
24
NewPic.Dispose();
25
Newms.Close();
26
return ChagedByte;
27
}
28![](/Images/OutliningIndicators/None.gif)
29
/// <summary>
30
/// 显示图片
31
/// </summary>
32
/// <param name="EmployeeID"></param>
33
public void GetPhoto(string EmployeeID, int height)
34
{
35
Bitmap bmp;
36
byte[] PhotoByte;
37
string cnstr;
38
string sql;
39
cnstr = "Data Source=localhost;Database=Northwind;uid=sa;pwd=123";
40
sql = "Select Photo From Employees Where EmplyeeID=" + EmployeeID;
41
using (SqlConnection cn = new SqlConnection(cnstr))
42
{
43
using (SqlCommand cmd = cn.CreateCommand())
44
{
45
cn.Open();
46
cmd.CommandText = sql;
47
using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
48
{
49
reader.Read();
50
PhotoByte = (byte[])reader.GetValue(0);
51
}
52
}
53
}
54
if (PhotoByte == null || PhotoByte.Length == 0) return;
55
MemoryStream tempStream = new MemoryStream(PhotoByte);
56
PhotoByte = LessonPicAutoWidth(tempStream, height);
57
bmp = new Bitmap(tempStream);
58
Response.ContentType = "image/gif";
59
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
60
Response.End();
61
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
2
![](/Images/OutliningIndicators/InBlock.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/InBlock.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/InBlock.gif)
26
![](/Images/OutliningIndicators/InBlock.gif)
27
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
28
![](/Images/OutliningIndicators/None.gif)
29
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
30
![](/Images/OutliningIndicators/InBlock.gif)
31
![](/Images/OutliningIndicators/InBlock.gif)
32
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
33
![](/Images/OutliningIndicators/None.gif)
34
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
35
![](/Images/OutliningIndicators/InBlock.gif)
36
![](/Images/OutliningIndicators/InBlock.gif)
37
![](/Images/OutliningIndicators/InBlock.gif)
38
![](/Images/OutliningIndicators/InBlock.gif)
39
![](/Images/OutliningIndicators/InBlock.gif)
40
![](/Images/OutliningIndicators/InBlock.gif)
41
![](/Images/OutliningIndicators/InBlock.gif)
42
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
43
![](/Images/OutliningIndicators/InBlock.gif)
44
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
45
![](/Images/OutliningIndicators/InBlock.gif)
46
![](/Images/OutliningIndicators/InBlock.gif)
47
![](/Images/OutliningIndicators/InBlock.gif)
48
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
49
![](/Images/OutliningIndicators/InBlock.gif)
50
![](/Images/OutliningIndicators/InBlock.gif)
51
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
52
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
53
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
54
![](/Images/OutliningIndicators/InBlock.gif)
55
![](/Images/OutliningIndicators/InBlock.gif)
56
![](/Images/OutliningIndicators/InBlock.gif)
57
![](/Images/OutliningIndicators/InBlock.gif)
58
![](/Images/OutliningIndicators/InBlock.gif)
59
![](/Images/OutliningIndicators/InBlock.gif)
60
![](/Images/OutliningIndicators/InBlock.gif)
61
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)