|
-
-
- <%@ WebHandler Language="VB" Class="DisplaySmallPicture" %>
- Option Strict On
- Imports System
- Imports System.IO
- Imports System.Drawing
- Imports System.Drawing.Imaging
- Imports System.Web
- Imports System.Data
- Imports System.Data.SqlClient
- Imports System.Web.Configuration
- Public Class DisplaySmallPicture
- Implements IHttpHandler
-
- Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
- ' 取得传递进来的文件路径。
- Dim PictureFilePath As String = Trim(context.Request.QueryString("PictureFilePath"))
-
- With context.Response
- ' 改变 HTTP 头的输出格式,以便让浏览器知道所输出的文档格式是 JPEG 格式。
- .ContentType = "Image/JPEG"
- .Clear()
- .BufferOutput = True
-
- Using ms As New MemoryStream(My.Computer.FileSystem.ReadAllBytes(PictureFilePath))
- Using bmp As New Bitmap(ms)
- Dim intWidh As Integer = 100
- Dim intHeight As Integer = CInt(bmp.Height / bmp.Width * 100)
-
- ' 将照片缩小。
- Using SmallerBmp As New Bitmap(bmp, CInt(intWidh), CInt(intHeight))
- 'Using SmallerBmp As New Bitmap(bmp, CInt(bmp.Width * 0.15), CInt(bmp.Height * 0.15))
- SmallerBmp.Save(.OutputStream, ImageFormat.Jpeg)
- End Using
- End Using
- End Using
- End With
- End Sub
-
- Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
- Get
- Return False
- End Get
- End Property
- End Class
-
复制代码 |
|