PrinceDotNet
یک شنبه 08 شهریور 1388, 16:02 عصر
سلام
من از کد زیر برای گرفتن عکس از بانک استفاده می کنم و توی خروجی handler قرار می دم!
<%@ WebHandler Language="VB" Class="Handler" %>
Imports System
Imports System.Web
Imports System.IO
Public Class Handler : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
' Set up the response settings
context.Response.ContentType = "image/jpeg"
context.Response.Cache.SetCacheability(HttpCacheab ility.Public)
context.Response.BufferOutput = False
Dim id As Int32 = 1
Dim stream As IO.Stream = Nothing
If Not String.IsNullOrEmpty(context.Request.QueryString("ImageID")) AndAlso Not context.Request.QueryString("ImageID") = 0 Then
Using db As New PhotoManagerTableAdapters.TableAdapter
id = [Convert].ToInt32(context.Request.QueryString("ImageID"))
stream = New MemoryStream(CType(db.GetUserImage(id), Byte()))
End Using
Else 'If Not String.IsNullOrEmpty(context.Request.QueryString("genedr")) Then
'Using db As New PhotoManagerTableAdapters.TableAdapter
'Dim gender As String = context.Request.QueryString("gedner")
'id = GetgednerID(gender)
'stream = New MemoryStream(CType(db.GetUserImage(id), Byte()))
'End Using
If String.IsNullOrEmpty(context.Request.QueryString("nophoto")) Then
stream = New MemoryStream(IO.File.ReadAllBytes(context.Request. MapPath(".") + "/images/nophoto.jpg"))
Else
stream = New MemoryStream(IO.File.ReadAllBytes(context.Request. MapPath(".") + "/images/spacer.gif"))
End If
End If
' Write image stream to the response stream
Dim buffersize As Integer = (1024 * 16)
Dim buffer() As Byte = New Byte((buffersize) - 1) {}
Dim count As Integer = stream.Read(buffer, 0, buffersize)
Do While (count > 0)
context.Response.OutputStream.Write(buffer, 0, count)
count = stream.Read(buffer, 0, buffersize)
Loop
End Sub
Private Function GetgednerID(ByVal gener As String) As Integer
If gener = "female" Then
Return 2
Else
Return 1
End If
End Function
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class
که db.GetUserImage دستوری هستش که image رو از بانک می گیره!
می خواستم بدونم می شه توی خروجی همین handler اندازه ی عکس رو 16*16 گذاشت ؟
من از کد زیر برای گرفتن عکس از بانک استفاده می کنم و توی خروجی handler قرار می دم!
<%@ WebHandler Language="VB" Class="Handler" %>
Imports System
Imports System.Web
Imports System.IO
Public Class Handler : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
' Set up the response settings
context.Response.ContentType = "image/jpeg"
context.Response.Cache.SetCacheability(HttpCacheab ility.Public)
context.Response.BufferOutput = False
Dim id As Int32 = 1
Dim stream As IO.Stream = Nothing
If Not String.IsNullOrEmpty(context.Request.QueryString("ImageID")) AndAlso Not context.Request.QueryString("ImageID") = 0 Then
Using db As New PhotoManagerTableAdapters.TableAdapter
id = [Convert].ToInt32(context.Request.QueryString("ImageID"))
stream = New MemoryStream(CType(db.GetUserImage(id), Byte()))
End Using
Else 'If Not String.IsNullOrEmpty(context.Request.QueryString("genedr")) Then
'Using db As New PhotoManagerTableAdapters.TableAdapter
'Dim gender As String = context.Request.QueryString("gedner")
'id = GetgednerID(gender)
'stream = New MemoryStream(CType(db.GetUserImage(id), Byte()))
'End Using
If String.IsNullOrEmpty(context.Request.QueryString("nophoto")) Then
stream = New MemoryStream(IO.File.ReadAllBytes(context.Request. MapPath(".") + "/images/nophoto.jpg"))
Else
stream = New MemoryStream(IO.File.ReadAllBytes(context.Request. MapPath(".") + "/images/spacer.gif"))
End If
End If
' Write image stream to the response stream
Dim buffersize As Integer = (1024 * 16)
Dim buffer() As Byte = New Byte((buffersize) - 1) {}
Dim count As Integer = stream.Read(buffer, 0, buffersize)
Do While (count > 0)
context.Response.OutputStream.Write(buffer, 0, count)
count = stream.Read(buffer, 0, buffersize)
Loop
End Sub
Private Function GetgednerID(ByVal gener As String) As Integer
If gener = "female" Then
Return 2
Else
Return 1
End If
End Function
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class
که db.GetUserImage دستوری هستش که image رو از بانک می گیره!
می خواستم بدونم می شه توی خروجی همین handler اندازه ی عکس رو 16*16 گذاشت ؟