Using response.write to display system.drawing.image

Discussion in 'ASP .Net' started by Dave Keen, Nov 26, 2006.

  1. Dave Keen

    Dave Keen Guest

    Hi all.

    Hope you can help me. This should be easy but I can't make this work.
    In brief I am building a page of thumbnails using images held in a
    SQLServer 2000 database. I do this by creating imagebuttons which
    point to a dummy page that takes the image and displays it via
    response. All works fine if I use explicit paths to a file
    (response.writefile(<filename>) or directly pass through the database
    image (response.binarywrite(<dbimage>), but I convert the db image to
    system.drawing.image so as to resize etc, and once I do that I can't
    display it.

    I have used the following code to take the database image, convert it
    into a system.drawing.image and show the results (this is obviously a
    cut down version of the original).

    Dim clsTableImage As New TableImage
    If clsTableImage.GetRecord(CType(1, Short)) = 0 Then
    ' Make an image object of the image using a stream
    Dim FullSizeImage As System.Drawing.Image
    Dim fs As New System.IO.MemoryStream
    Dim w As New System.IO.BinaryWriter(fs)
    w.Write(clsTableImage.Image)
    FullSizeImage = System.Drawing.Image.FromStream(fs)

    'Response.ContentType = "image/jpeg"
    Response.Write(FullSizeImage)
    End If

    clsTableImage is a class that returns the image as a byte array. What
    I get out of this is the text "system.drawing.bitmap". So, how do I
    send a system.drawing.image to the form in ASP 1.1?

    Thanks in advance.

    Dave
     
    Dave Keen, Nov 26, 2006
    #1
    1. Advertising

  2. You would typically Response.Write the byte array itself.
    No need to create an image from it.

    --
    Robbe Morris - 2004-2006 Microsoft MVP C#
    I've mapped the database to .NET class properties and methods to
    implement an multi-layered object oriented environment for your
    data access layer. Thus, you should rarely ever have to type the words
    SqlCommand, SqlDataAdapter, or SqlConnection again.
    http://www.eggheadcafe.com/articles/adonet_source_code_generator.asp





    "Dave Keen" <> wrote in message
    news:...
    > Hi all.
    >
    > Hope you can help me. This should be easy but I can't make this work.
    > In brief I am building a page of thumbnails using images held in a
    > SQLServer 2000 database. I do this by creating imagebuttons which
    > point to a dummy page that takes the image and displays it via
    > response. All works fine if I use explicit paths to a file
    > (response.writefile(<filename>) or directly pass through the database
    > image (response.binarywrite(<dbimage>), but I convert the db image to
    > system.drawing.image so as to resize etc, and once I do that I can't
    > display it.
    >
    > I have used the following code to take the database image, convert it
    > into a system.drawing.image and show the results (this is obviously a
    > cut down version of the original).
    >
    > Dim clsTableImage As New TableImage
    > If clsTableImage.GetRecord(CType(1, Short)) = 0 Then
    > ' Make an image object of the image using a stream
    > Dim FullSizeImage As System.Drawing.Image
    > Dim fs As New System.IO.MemoryStream
    > Dim w As New System.IO.BinaryWriter(fs)
    > w.Write(clsTableImage.Image)
    > FullSizeImage = System.Drawing.Image.FromStream(fs)
    >
    > 'Response.ContentType = "image/jpeg"
    > Response.Write(FullSizeImage)
    > End If
    >
    > clsTableImage is a class that returns the image as a byte array. What
    > I get out of this is the text "system.drawing.bitmap". So, how do I
    > send a system.drawing.image to the form in ASP 1.1?
    >
    > Thanks in advance.
    >
    > Dave
    >
     
    Robbe Morris [C# MVP], Nov 27, 2006
    #2
    1. Advertising

  3. Dave Keen

    Dave Keen Guest

    Hi Robbe

    Thanks for your thoughts. Unfortunately I have to convert to an image
    object as I want to resize and manipulate the image before showing it.
    Remember I said the code I gave was a simplified version. After I take
    the byte array and convert to an image which I have changed in various
    ways I need to pass that image object to the form. How?

    Cheers

    Dave


    Robbe Morris [C# MVP] wrote:
    > You would typically Response.Write the byte array itself.
    > No need to create an image from it.
    >
    > --
    > Robbe Morris - 2004-2006 Microsoft MVP C#
    > I've mapped the database to .NET class properties and methods to
    > implement an multi-layered object oriented environment for your
    > data access layer. Thus, you should rarely ever have to type the words
    > SqlCommand, SqlDataAdapter, or SqlConnection again.
    > http://www.eggheadcafe.com/articles/adonet_source_code_generator.asp
    >
    >
    >
    >
    >
    > "Dave Keen" <> wrote in message
    > news:...
    > > Hi all.
    > >
    > > Hope you can help me. This should be easy but I can't make this work.
    > > In brief I am building a page of thumbnails using images held in a
    > > SQLServer 2000 database. I do this by creating imagebuttons which
    > > point to a dummy page that takes the image and displays it via
    > > response. All works fine if I use explicit paths to a file
    > > (response.writefile(<filename>) or directly pass through the database
    > > image (response.binarywrite(<dbimage>), but I convert the db image to
    > > system.drawing.image so as to resize etc, and once I do that I can't
    > > display it.
    > >
    > > I have used the following code to take the database image, convert it
    > > into a system.drawing.image and show the results (this is obviously a
    > > cut down version of the original).
    > >
    > > Dim clsTableImage As New TableImage
    > > If clsTableImage.GetRecord(CType(1, Short)) = 0 Then
    > > ' Make an image object of the image using a stream
    > > Dim FullSizeImage As System.Drawing.Image
    > > Dim fs As New System.IO.MemoryStream
    > > Dim w As New System.IO.BinaryWriter(fs)
    > > w.Write(clsTableImage.Image)
    > > FullSizeImage = System.Drawing.Image.FromStream(fs)
    > >
    > > 'Response.ContentType = "image/jpeg"
    > > Response.Write(FullSizeImage)
    > > End If
    > >
    > > clsTableImage is a class that returns the image as a byte array. What
    > > I get out of this is the text "system.drawing.bitmap". So, how do I
    > > send a system.drawing.image to the form in ASP 1.1?
    > >
    > > Thanks in advance.
    > >
    > > Dave
    > >
     
    Dave Keen, Nov 27, 2006
    #3
  4. Dave Keen

    Dave Keen Guest

    Hi Robbe

    Thanks for your thoughts. Unfortunately I have to convert to an image
    object as I want to resize and manipulate the image before showing it.
    Remember I said the code I gave was a simplified version. After I take
    the byte array and convert to an image which I have changed in various
    ways I need to pass that image object to the form. How?

    Cheers

    Dave


    Robbe Morris [C# MVP] wrote:
    > You would typically Response.Write the byte array itself.
    > No need to create an image from it.
    >
    > --
    > Robbe Morris - 2004-2006 Microsoft MVP C#
    > I've mapped the database to .NET class properties and methods to
    > implement an multi-layered object oriented environment for your
    > data access layer. Thus, you should rarely ever have to type the words
    > SqlCommand, SqlDataAdapter, or SqlConnection again.
    > http://www.eggheadcafe.com/articles/adonet_source_code_generator.asp
    >
    >
    >
    >
    >
    > "Dave Keen" <> wrote in message
    > news:...
    > > Hi all.
    > >
    > > Hope you can help me. This should be easy but I can't make this work.
    > > In brief I am building a page of thumbnails using images held in a
    > > SQLServer 2000 database. I do this by creating imagebuttons which
    > > point to a dummy page that takes the image and displays it via
    > > response. All works fine if I use explicit paths to a file
    > > (response.writefile(<filename>) or directly pass through the database
    > > image (response.binarywrite(<dbimage>), but I convert the db image to
    > > system.drawing.image so as to resize etc, and once I do that I can't
    > > display it.
    > >
    > > I have used the following code to take the database image, convert it
    > > into a system.drawing.image and show the results (this is obviously a
    > > cut down version of the original).
    > >
    > > Dim clsTableImage As New TableImage
    > > If clsTableImage.GetRecord(CType(1, Short)) = 0 Then
    > > ' Make an image object of the image using a stream
    > > Dim FullSizeImage As System.Drawing.Image
    > > Dim fs As New System.IO.MemoryStream
    > > Dim w As New System.IO.BinaryWriter(fs)
    > > w.Write(clsTableImage.Image)
    > > FullSizeImage = System.Drawing.Image.FromStream(fs)
    > >
    > > 'Response.ContentType = "image/jpeg"
    > > Response.Write(FullSizeImage)
    > > End If
    > >
    > > clsTableImage is a class that returns the image as a byte array. What
    > > I get out of this is the text "system.drawing.bitmap". So, how do I
    > > send a system.drawing.image to the form in ASP 1.1?
    > >
    > > Thanks in advance.
    > >
    > > Dave
    > >
     
    Dave Keen, Nov 27, 2006
    #4
  5. Dave Keen

    nishant

    Joined:
    Mar 31, 2009
    Messages:
    2
    Nishant makvana

    Dim FullSizeImage As System.Drawing.Image
    Dim fs As New System.IO.MemoryStream
    Dim w As New System.IO.BinaryWriter(fs)
    w.Write(clsTableImage.Image)
    FullSizeImage = System.Drawing.Image.FromStream(fs)
    FullSizeImage.Save(Server.MapPath("~/destinationFolder/imagename.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
    ASPNETImageControl.ImageUrl = "~/destinationFolder/imagename.jpg";
     
    nishant, Mar 31, 2009
    #5
  6. Dave Keen

    nishant

    Joined:
    Mar 31, 2009
    Messages:
    2
    Display System.Drawing.Image in ASP.NET Image Cotrol

    Dim FullSizeImage As System.Drawing.Image
    Dim fs As New System.IO.MemoryStream
    Dim w As New System.IO.BinaryWriter(fs)
    w.Write(clsTableImage.Image)
    FullSizeImage = System.Drawing.Image.FromStream(fs)
    FullSizeImage.Save(Server.MapPath("~/destinationFolder/imagename.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
    ASPNETImageControl.ImageUrl = "~/destinationFolder/imagename.jpg";

    Now you can See the image in your own webpage and in image control.

    Display
     
    nishant, Mar 31, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. anastasia
    Replies:
    4
    Views:
    17,593
    atalas
    Apr 18, 2008
  2. Replies:
    1
    Views:
    654
    Kevin Spencer
    Jan 9, 2006
  3. byrd48
    Replies:
    0
    Views:
    3,578
    byrd48
    Jul 6, 2006
  4. Replies:
    1
    Views:
    843
  5. defn noob
    Replies:
    1
    Views:
    407
    Mark Space
    Jun 28, 2008
Loading...

Share This Page