【 tulaoshi.com - ASP.NET 】
在sqlserver中的图片类型是image
然后,通过dataset保存到数据库中,通过showimg.aspx文件来读出图片,即显示图片,代码如下:
Dim image As Byte() = IssueQuestionRow.QuestionImage
'/转换为支持存储区为内存的流
Dim memStream As New System.IO.MemoryStream(image)
'/定义并实例化Bitmap对象
Dim bm As New Bitmap(memStream)
'/根据不同的条件进行输出或者下载;
Response.Clear()
'/如果请求字符串指定下载,就下载该文件;
'/否则,就显示在浏览器中。
If Request.QueryString("Download") = "1" Then
Response.Buffer = True
Response.ContentType = "application/octet-stream"
'/这里下载输出的文件名字 ok.jpg 为例子,你实际中可以根据情况动态决定。
Response.AddHeader("Content-Disposition", "attachment;filename=ok.jpg")
Else
Response.ContentType = "image/jpg"
End If
Response.BinaryWrite(image)
Response.End()
然后通过需要调用显示图片的页面,加入
ChapterID = Request.QueryString("ChapterID")
Exercise = EXH.GetExercise(ChapterID)
Dim dv As New DataView(Exercise.Ex_IssueQuestion)
dv.RowFilter = "QuestionID='" + QuestionID + "'"
If dv.Count > 0 Then
IssueQuestionRow = dv.Item(0).Row
Dim image As Byte() = IssueQuestionRow.QuestionImage
'/转换为支持存储区为内存的流
Dim memStream As New System.IO.MemoryStream(image)
'/定义并实例化Bitmap对象
Dim bm As New Bitmap(memStream)
'/根据不同的条件进行输出或者下载;
Response.BinaryWrite(image)
End If
End If
End Sub
在其他需要调用的地方的aspx页面里只需写:
来源:http://www.tulaoshi.com/n/20160129/1489673.html