📄 showimagevb.aspx.vb
字号:
Imports System.IO
Imports System.Data.OleDb
Namespace Telerik.UploadExamplesVBNet.PhotoGallery
Public Class ShowImageVB
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Get the file information from the database
Dim conn As OleDbConnection = New OleDbConnection(DefaultVB.GetConnectionString(Request))
conn.Open()
If Request.QueryString("imgid") Is Nothing Then
WriteImage(GetEmptyImage(), "NoImage")
Return
End If
Dim query As String = "SELECT {0}, [Name] FROM Images WHERE ImageID = ?"
'Check if to get the thumbnail of a file, or to get the full file
If (Not Request.QueryString("type") Is Nothing) And Request.QueryString("type") = "thumb" Then
query = String.Format(query, "Thumbnail")
Else
query = String.Format(query, "[Image]")
End If
'Get the image and display it
Dim command As OleDbCommand = New OleDbCommand(query, conn)
command.Parameters.Add("@ImageID", Integer.Parse(Request.QueryString("imgid")))
Dim reader As OleDbDataReader = command.ExecuteReader()
If reader.Read() Then
WriteImage(CType(reader(0), Byte()), reader(1).ToString())
reader.Close()
Else
'There was not such an image, so display the no_image image
WriteImage(GetEmptyImage(), "NoImage")
End If
End Sub
Private Sub WriteImage(ByVal image As Byte(), ByVal fileName As String)
Response.Buffer = True
Response.Clear()
Response.ContentType = "image/gif"
Response.AddHeader("content-disposition", "inline; filename=" + fileName)
Response.BinaryWrite(image)
Response.Flush()
Response.End()
End Sub
Private Function GetEmptyImage() As Byte()
Dim height As Integer = DefaultVB.MAX_THUMBNAIL_HEIGHT
Dim width As Integer = DefaultVB.MAX_THUMBNAIL_WIDTH
Dim empty As Bitmap = New Bitmap(width, height)
Dim ms As MemoryStream = New MemoryStream
empty.Save(ms, System.Drawing.Imaging.ImageFormat.Gif)
Return ms.ToArray()
End Function
End Class
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -