Response.OutputStream

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jenny

    #1

    Response.OutputStream

    Hi all,

    I'm using a second page to write dynamical generated images
    into the outputstream. This avoids using tmp-files on disc.

    My code-behind in the start aspx file is:

    'Use second file to write into outputstream
    Application("gr afix-obj") = ob
    button.ImageUrl = "Grafix.asp x"
    Panel.Controls. Add(button)

    ob is the bitmap with the image! The file Grafix.aspx
    contains only code behind:

    Public Class grafix
    Inherits System.Web.UI.P age

    #Region " Web Form Designer Generated Code "

    ......

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal
    e As System.EventArg s) Handles MyBase.Load

    Dim ob As Bitmap = New Bitmap(830, 30)
    ob = CType(Applicati on("grafix-obj"), Bitmap)
    ob.Save(Respons e.OutputStream, Imaging.ImageFo rmat.Jpeg)
    End Sub

    End Class

    I normally expect this to be working! But there is only the
    'no image' sign on the imagebutton if I try.
    I used the following code before, which worked well:

    'Store as tmp file on disk
    Dim tempfilepath As String = System.IO.Path. GetTempPath
    ob.Save(tempfil epath &"temp.jpg",Ima ging.ImageForma t.Jpeg
    button.ImageUrl = tempfilepath & "temp.jpg"

    What is going wrong?

    Thanks for each help
    Jenny
  • Roberto López

    #2
    Re: Response.Output Stream

    IN the Image.Save method, save it to a MemoryStream and after write the
    memorystream to the response.output stream of the page.

    Dim memstr as new memorystream()
    Image.Save(mems tr,imageformat. jpeg)
    memstr.writeto( response.output stream)


    "Jenny" <j.malloyNO@SPA Mx-mail.ent> escribió en el mensaje
    news:04a201c35a 5c$fd21fce0$a40 1280a@phx.gbl.. .[color=blue]
    > Hi all,
    >
    > I'm using a second page to write dynamical generated images
    > into the outputstream. This avoids using tmp-files on disc.
    >
    > My code-behind in the start aspx file is:
    >
    > 'Use second file to write into outputstream
    > Application("gr afix-obj") = ob
    > button.ImageUrl = "Grafix.asp x"
    > Panel.Controls. Add(button)
    >
    > ob is the bitmap with the image! The file Grafix.aspx
    > contains only code behind:
    >
    > Public Class grafix
    > Inherits System.Web.UI.P age
    >
    > #Region " Web Form Designer Generated Code "
    >
    > .....
    >
    > #End Region
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal
    > e As System.EventArg s) Handles MyBase.Load
    >
    > Dim ob As Bitmap = New Bitmap(830, 30)
    > ob = CType(Applicati on("grafix-obj"), Bitmap)
    > ob.Save(Respons e.OutputStream, Imaging.ImageFo rmat.Jpeg)
    > End Sub
    >
    > End Class
    >
    > I normally expect this to be working! But there is only the
    > 'no image' sign on the imagebutton if I try.
    > I used the following code before, which worked well:
    >
    > 'Store as tmp file on disk
    > Dim tempfilepath As String = System.IO.Path. GetTempPath
    > ob.Save(tempfil epath &"temp.jpg",Ima ging.ImageForma t.Jpeg
    > button.ImageUrl = tempfilepath & "temp.jpg"
    >
    > What is going wrong?
    >
    > Thanks for each help
    > Jenny[/color]


    Comment

    • Michal A. Valasek

      #3
      Re: Response.Output Stream

      | Private Sub Page_Load(ByVal sender As System.Object, ByVal
      | e As System.EventArg s) Handles MyBase.Load
      |
      | Dim ob As Bitmap = New Bitmap(830, 30)
      | ob = CType(Applicati on("grafix-obj"), Bitmap)
      | ob.Save(Respons e.OutputStream, Imaging.ImageFo rmat.Jpeg)
      | End Sub
      |
      | End Class
      |
      | I normally expect this to be working! But there is only the
      | 'no image' sign on the imagebutton if I try.

      Similar code works well for me, just specify content-type:
      Response.Conten tType = "image/jpeg".

      The following is code I use at http://webcam.rider.cz:

      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
      System.EventArg s) Handles MyBase.Load
      Dim BMP As Bitmap, GPH As Graphics
      Dim RQ As System.Net.Http WebRequest
      Dim RP As System.Net.Http WebResponse

      Response.Conten tType = "image/jpeg"
      Try
      RQ = System.Net.WebR equest.Create(" http://epona:8000/" &
      Request.UserHos tAddress)
      RQ.UserAgent = Request.UserAge nt
      RP = RQ.GetResponse( )
      BMP = New Bitmap(RP.GetRe sponseStream())
      GPH = System.Drawing. Graphics.FromIm age(BMP)
      Catch EX As Exception
      BMP = BMP.FromFile(Se rver.MapPath("/_gfx/wc-error.bmp"))
      GPH = System.Drawing. Graphics.FromIm age(BMP)
      GPH.DrawString( "The following exception occured:" & vbCrLf &
      EX.Message, New Font("Courier New", 10, FontStyle.Bold, GraphicsUnit.Po int),
      New SolidBrush(Colo r.White), 5, 400)
      End Try
      GPH.DrawImage(N ew Bitmap(Server.M apPath("/_gfx/wc-footer.bmp")), New
      RectangleF(0, 460, 640, 20), New RectangleF(0, 0, 640, 20),
      GraphicsUnit.Pi xel)
      GPH.DrawString( "www.rider. cz | Prague CZ-EU | " &
      Now.ToUniversal Time.ToString(" yyyy-MM-dd HH:mm:ss") & " GMT", New
      Font("Courier New", 10, FontStyle.Bold, GraphicsUnit.Po int), New
      SolidBrush(Colo r.White), 5, 462)
      BMP.Save(Respon se.OutputStream ,
      System.Drawing. Imaging.ImageFo rmat.Jpeg)
      End Sub

      --
      Michal A. Valasek, Altair Communications, http://www.altaircom.net
      Please do not reply to this e-mail, for contact see http://www.rider.cz


      Comment

      • vMike

        #4
        Re: Response.Output Stream

        Here is how I did it. I didn't bother with code behind on this one because
        there isn't anything other than code. I call the image by setting it's
        ImageURL or NavigateURLprop erty to
        pic.aspx?_p=abc .jpg&_w=123&_h= 123&_q=1 (for image, or 2 for thumb)

        <%@ Page Language="VB" SmartNavigation ="false" Strict="true" %>
        <%@ import Namespace="Syst em.Drawing" %>
        <%@ import Namespace="Syst em.Drawing.Imag ing" %>
        <%@ import Namespace="Syst em.Drawing.Draw ing2D" %>


        <html>

        <script language="vb" runat="server">
        sub Page_Load(sende r as object, e as eventArgs)

        dim strPic as string = request.queryst ring("_p")
        dim intWidth as int32 = ctype(request.q uerystring("_w" ),int32)
        dim intHeight as int32 = ctype(request.q uerystring("_h" ),int32)
        dim intQuality as int32 = ctype(request.q uerystring("_q" ),int32)
        dim myNewImage as system.drawing. image
        dim strFileLoc as string =
        server.mappath( configurationSe ttings.AppSetti ngs("picroot"))


        try
        select case intQuality
        case is = 1
        if intWidth = 0 then intWidth = 200
        if intHeight = 0 then intHeight = 200

        mynewimage = mgAdjustBitmap( strFileLoc & strPic, intWidth, intHeight)
        case else
        if intWidth = 0 then intWidth = 90
        if intHeight = 0 then intHeight = 90
        mynewimage = mggetthumbnail( strFileLoc & strPic,intWidth ,intHeight)

        end select
        mynewimage.Save (Response.Outpu tStream, ImageFormat.Jpe g)
        catch
        mynewimage= mggetthumbnail( strFileLoc & "npicture.jpg", 90,90)
        mynewimage.Save (Response.Outpu tStream, ImageFormat.Jpe g)
        end try
        End Sub

        Function mgGetThumbNail( strFile as string, intWidth as integer, intHeight as
        integer) as system.drawing. image
        Dim myBitmap As bitmap = New Bitmap(strFile)
        return mybitmap.getthu mbnailimage(int Width,intHeight ,nothing,nothin g)
        mybitmap.dispos e
        End Function

        Function mgAdjustBitmap( strFile as string, intHorz as integer, intVert as
        integer) as bitmap

        Dim mysize as size = new size(inthorz,in tVert)
        Dim myBitmap As bitmap = New Bitmap(strFile)
        dim myImg as bitmap = new bitmap(mybitmap , mysize)
        mybitmap.dispos e
        return myImg
        End Function
        </script>

        </html>
        "Jenny" <j.malloyNO@SPA Mx-mail.ent> wrote in message
        news:04a201c35a 5c$fd21fce0$a40 1280a@phx.gbl.. .[color=blue]
        > Hi all,
        >
        > I'm using a second page to write dynamical generated images
        > into the outputstream. This avoids using tmp-files on disc.
        >
        > My code-behind in the start aspx file is:
        >
        > 'Use second file to write into outputstream
        > Application("gr afix-obj") = ob
        > button.ImageUrl = "Grafix.asp x"
        > Panel.Controls. Add(button)
        >
        > ob is the bitmap with the image! The file Grafix.aspx
        > contains only code behind:
        >
        > Public Class grafix
        > Inherits System.Web.UI.P age
        >
        > #Region " Web Form Designer Generated Code "
        >
        > .....
        >
        > #End Region
        >
        > Private Sub Page_Load(ByVal sender As System.Object, ByVal
        > e As System.EventArg s) Handles MyBase.Load
        >
        > Dim ob As Bitmap = New Bitmap(830, 30)
        > ob = CType(Applicati on("grafix-obj"), Bitmap)
        > ob.Save(Respons e.OutputStream, Imaging.ImageFo rmat.Jpeg)
        > End Sub
        >
        > End Class
        >
        > I normally expect this to be working! But there is only the
        > 'no image' sign on the imagebutton if I try.
        > I used the following code before, which worked well:
        >
        > 'Store as tmp file on disk
        > Dim tempfilepath As String = System.IO.Path. GetTempPath
        > ob.Save(tempfil epath &"temp.jpg",Ima ging.ImageForma t.Jpeg
        > button.ImageUrl = tempfilepath & "temp.jpg"
        >
        > What is going wrong?
        >
        > Thanks for each help
        > Jenny[/color]


        Comment

        Working...