<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      保存圖片流到數據庫之后固定顯示新法

      [摘要]在sqlserver中的圖片類型是image然后,通過dataset保存到數據庫中,通過showimg.aspx文件來讀出圖片,即顯示圖片,代碼如下: Dim image As Byte() = IssueQuestionRow.QuestionImage &#...

      在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()


      然后通過需要調用顯示圖片的頁面,加入 <img src=”./showimg.aspx” wigth=”100px” height=”50”>
      來固定圖片的顯示位置、大小等。
      當然也可以通過一個頁面的不同參數來獲得不同的圖片,如下代碼:
      Showimg.aspx文件:
        Public QuestionID As String
          Public ChapterID As String
          Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
              '在此處放置初始化頁的用戶代碼
              If Not IsPostBack Then
                  QuestionID = Request.QueryString("QID")
                  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頁面里只需寫:<img src=”./showimg.aspx?QuestionID=222&ChapterID=3” wigth=”100px” height=”50”>即可


       




      日韩精品一区二区三区高清