📄 showimagevb.aspx.vb
字号:
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Data.OleDb
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.IO
Namespace Telerik.EditorExamplesVBNET.Editor.Examples.DBImages
Public Class ShowImage
Inherits System.Web.UI.Page
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 New OleDbConnection(DefaultVB.ConnectionString)
conn.Open()
If Request.QueryString("file") Is Nothing Then
WriteImage(GetEmptyImage())
Return
End If
Dim query As String = "SELECT {0} FROM Images WHERE FileName = '" + Request.QueryString("file").Replace("'", "''") + "'"
'Check if to get the thumbnail of a file, or to get the full file
If Not (Request.QueryString("type") Is Nothing) AndAlso Request.QueryString("type") = "thumb" Then
query = String.Format(query, "Thumbnail")
Else
query = String.Format(query, "FullImage")
End If
'Get the image and display it
Dim command As New OleDbCommand(query, conn)
Dim reader As OleDbDataReader = command.ExecuteReader()
If reader.Read() Then
WriteImage(CType(reader(0), Byte()))
Else
'There was not such an image, so display the no_image image
WriteImage(GetEmptyImage())
End If
End Sub 'Page_Load
'/ <summary>
'/ Flushes a byte array to the output stream
'/ </summary>
'/ <param name="image"></param>
Private Sub WriteImage(ByVal image() As Byte)
Response.Buffer = True
Response.Clear()
Response.ContentType = "image/gif"
Response.AddHeader("content-disposition", "attachment; filename=" + Request.QueryString("FileName"))
Response.BinaryWrite(image)
Response.Flush()
Response.End()
End Sub 'WriteImage
'/ <summary>
'/ Creates an empty bitmap image and returns it as an array of bytes
'/ </summary>
'/ <returns></returns>
Private Function GetEmptyImage() As Byte()
Dim height As Integer = DefaultVB.ThumbsHeight
Dim width As Integer = DefaultVB.ThumbsWidth
Dim empty As New Bitmap(width, height)
Dim ms As New MemoryStream
empty.Save(ms, System.Drawing.Imaging.ImageFormat.Gif)
Return ms.ToArray()
End Function 'GetEmptyImage
#Region "Web Form Designer generated code"
Protected Overrides Sub OnInit(ByVal e As EventArgs)
InitializeComponent()
MyBase.OnInit(e)
End Sub 'OnInit
Private Sub InitializeComponent()
End Sub 'InitializeComponent
#End Region
End Class 'ShowImage
End Namespace 'DBImages
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -