Question on rendering images from SQL database

Discussion in 'ASP .Net' started by Blasting Cap, Oct 25, 2006.

  1. Blasting Cap

    Blasting Cap Guest

    I am using the following code to pull an image out of a database &
    display it on a web page.

    Dim data As New data
    Dim sID As String = Request.Params("itemID")
    Dim sqlConnection As New SqlConnection(data.connectionString)
    Dim sqlCom As New SqlCommand("Select Data, Type From tblImageStorage
    Where (Story_ID='" & sID & "')", sqlConnection)
    Dim sqlDataReader As SqlDataReader
    sqlConnection.Open()
    sqlDataReader = sqlCom.ExecuteReader
    sqlDataReader.Read()
    Dim byteArray As Byte() = CType(sqlDataReader("Data"), Byte())
    Dim mstream As System.IO.MemoryStream = New
    System.IO.MemoryStream(byteArray, 0, byteArray.Length)
    Dim dbImage As System.Drawing.Image =
    System.Drawing.Image.FromStream(New System.IO.MemoryStream(byteArray))
    Dim bmp As Bitmap = New Bitmap(dbImage)
    Dim scale As Single = 300.0F / System.Math.Max(0, bmp.Width)
    Dim thumbnailImage As System.Drawing.Image =
    bmp.GetThumbnailImage(CType((bmp.Width * scale), Integer),
    CType((bmp.Height * scale), Integer), Nothing, System.IntPtr.Zero)
    thumbnailImage.Save(Context.Response.OutputStream,
    System.Drawing.Imaging.ImageFormat.Jpeg)
    sqlConnection.Close()


    It works fine & displays the image fine.

    However, the application I have needs to have the ability to read a
    story out of the same sql database & display it. It seems that I can
    only do one thing.

    How can you display the graphic read from a SQL database AND the story
    associated with it on the same page?

    As an added "oddity" I have noticed that on the rendered page, that
    "View Source" is not available from the file/edit/view menu. Do not
    know if that means anything or not.

    Any help appreciated.

    BC
    Blasting Cap, Oct 25, 2006
    #1
    1. Advertising

  2. you only get one item per response. if you to return text and an image (at
    least with IE), you need to return html with a image tag with a reference to
    the image url.if you google this newgroup for sqlserver image, you will get
    details.

    -- bruce (sqlwork.com)

    "Blasting Cap" <> wrote in message
    news:eyjtc4F%...
    >
    > I am using the following code to pull an image out of a database & display
    > it on a web page.
    >
    > Dim data As New data
    > Dim sID As String = Request.Params("itemID")
    > Dim sqlConnection As New SqlConnection(data.connectionString)
    > Dim sqlCom As New SqlCommand("Select Data, Type From tblImageStorage Where
    > (Story_ID='" & sID & "')", sqlConnection)
    > Dim sqlDataReader As SqlDataReader
    > sqlConnection.Open()
    > sqlDataReader = sqlCom.ExecuteReader
    > sqlDataReader.Read()
    > Dim byteArray As Byte() = CType(sqlDataReader("Data"), Byte())
    > Dim mstream As System.IO.MemoryStream = New
    > System.IO.MemoryStream(byteArray, 0, byteArray.Length)
    > Dim dbImage As System.Drawing.Image =
    > System.Drawing.Image.FromStream(New System.IO.MemoryStream(byteArray))
    > Dim bmp As Bitmap = New Bitmap(dbImage)
    > Dim scale As Single = 300.0F / System.Math.Max(0, bmp.Width)
    > Dim thumbnailImage As System.Drawing.Image =
    > bmp.GetThumbnailImage(CType((bmp.Width * scale), Integer),
    > CType((bmp.Height * scale), Integer), Nothing, System.IntPtr.Zero)
    > thumbnailImage.Save(Context.Response.OutputStream,
    > System.Drawing.Imaging.ImageFormat.Jpeg)
    > sqlConnection.Close()
    >
    >
    > It works fine & displays the image fine.
    >
    > However, the application I have needs to have the ability to read a story
    > out of the same sql database & display it. It seems that I can only do
    > one thing.
    >
    > How can you display the graphic read from a SQL database AND the story
    > associated with it on the same page?
    >
    > As an added "oddity" I have noticed that on the rendered page, that "View
    > Source" is not available from the file/edit/view menu. Do not know if
    > that means anything or not.
    >
    > Any help appreciated.
    >
    > BC
    >
    >
    >
    bruce barker \(sqlwork.com\), Oct 25, 2006
    #2
    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. Peter Mount
    Replies:
    4
    Views:
    947
    Peter Mount
    Jan 31, 2006
  2. Universal
    Replies:
    1
    Views:
    593
    Lionel B
    Apr 8, 2005
  3. Universal
    Replies:
    0
    Views:
    452
    Universal
    Apr 8, 2005
  4. Just Me
    Replies:
    2
    Views:
    532
    John Mott
    Sep 4, 2007
  5. ccc31807

    rendering images from a database

    ccc31807, Nov 3, 2009, in forum: Perl Misc
    Replies:
    0
    Views:
    78
    ccc31807
    Nov 3, 2009
Loading...

Share This Page