none
Bildgröße manipulieren RRS feed

  • Frage

  • Hallo,

    ich lade mittels Handler ein Bild aus einer Datenbank. Wie kann ich Höhe und Breite des Bildes manipulieren? Der Code des Handlers ist wie folgt:

     

    <%@ WebHandler Language="VB" Class="MyBild" %>

     

    Imports System

    Imports System.Web

    Imports System.Data.SqlClient

    Imports System.Data

     

    Public Class MyBild : Implements IHttpHandler

       

        Private ReadOnly Property ConnectionString() As String

            Get

                Return "Server=.\SQLEXPRESS;Database=Bilder;Trusted_Connection=True"

            End Get

        End Property

       

        Private ReadOnly Property Connection() As SqlConnection

            Get

                Dim MyConnection As New SqlConnection(ConnectionString)

                MyConnection.Open()

                Return MyConnection

            End Get

        End Property

       

        Public Function GetData(ByVal Id As String) As DataSet

            Dim SelectQry = " SELECT Bild FROM Personen WHERE Id =" & Id

          

            Dim MyDataSource As New DataSet

            Try

                Dim MyDataAdapter As New SqlDataAdapter(SelectQry, ConnectionString)

                MyDataAdapter.Fill(MyDataSource)

            Catch ex As Exception

                Throw ex

            End Try

            Return MyDataSource

        End Function

       

        Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

            context.Response.Clear()

            context.Response.ContentType = "image/jpeg"

            Dim ImageBuffer As Byte()

            Dim FahrerId As String = context.Request.Params("Id")

            ImageBuffer = GetData(FahrerId).Tables(0).Rows(0)("Bild")

            context.Response.OutputStream.Write(ImageBuffer, 0, ImageBuffer.Length)

            context.Response.End()

        End Sub

     

        Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable

            Get

                Return False

            End Get

        End Property

    End Class

    Gruß Wulf

    Donnerstag, 27. Oktober 2011 18:25

Antworten

Alle Antworten