SQL image
SQL image
SQL image
SQL image
SQL image
SQL image SQL image SQL image SQL image SQL image SQL image SQL image SQL image
SQL image SQL image
SQL image
Go Back  Xtreme Visual Basic Talk > > > SQL image


Reply
 
Thread Tools Display Modes
  #1  
Old 10-29-2008, 03:58 PM
nate's Avatar
nate nate is offline
Junior Contributor
 
Join Date: Mar 2001
Posts: 358
Default SQL image


Please help,
I found alot of sample on the web on how to save and display images from SQL. I can successfully save the image. But when I go to display it from my db it wipes my page out and displays the image only. I simply want to display the image in my image control on my page and not lose all page data. I assume this has to do with the response, but I can't seem to get it to work. Thanks.

Code:
Dim stream As New MemoryStream()
        Try
            Dim image As Byte() = DirectCast(Recordset.Fields.Item("myimage").Value, Byte())
            stream.Write(image, 0, image.Length)
            Dim bitmap As New Bitmap(stream)
            Response.ContentType = "image/gif"
            bitmap.Save(Response.OutputStream, ImageFormat.Gif)
        Finally
            stream.Close()
        End Try
__________________
Ignorance begins with I.
Reply With Quote
  #2  
Old 10-29-2008, 04:25 PM
nate's Avatar
nate nate is offline
Junior Contributor
 
Join Date: Mar 2001
Posts: 358
Default

OK, I got it. Use the page as the image.url, then change page context on load. Thanks.
__________________
Ignorance begins with I.
Reply With Quote
  #3  
Old 11-05-2008, 06:09 AM
John_0025 John_0025 is offline
Freshman
 
Join Date: Sep 2003
Posts: 39
Default

I see that you have already solved the problem but you can use a handler rather than a page to get the image.

For example:
The markup would be the same
Code:
<img src="image.aspx" />
Add a handler to your web.config file
Code:
<add verb="GET" path="image.aspx" type="ImageHandlerDemo.ImageHandler, ImageHandlerDemo"/>
The class the handle the request
Code:
    Public Class ImageHandler
        Implements IHttpHandler

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

            Dim imageType As ImageFormat = ImageFormat.Gif
            Dim contentType As String = "image/" + imageType.ToString
            context.Response.Clear()
            context.Response.ContentType = contentType

            context.Response.AddHeader("Content-Type", contentType)
            context.Response.AddHeader("Content-Disposition", "attachment; filename=picture." + imageType.ToString().ToLower())

            Dim stream As New MemoryStream()
            Try
                Dim image As Byte() = DirectCast(Recordset.Fields.Item("myimage").Value, Byte())
                stream.Write(image, 0, image.Length)
                Dim bitmap As New Bitmap(stream)
                bitmap.Save(context.Response.OutputStream, ImageFormat.Gif)
            Finally
                stream.Close()
            End Try

            context.Response.Flush()
        End Sub

        Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
            Get
                Return True
            End Get
        End Property

    End Class
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
SQL image
SQL image
SQL image SQL image
SQL image
SQL image
SQL image SQL image SQL image SQL image SQL image SQL image SQL image
SQL image
SQL image
 
SQL image
SQL image
 
-->