Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET - Thumbnail images from Access Database 1

Status
Not open for further replies.

gsgb1

Programmer
Jul 31, 2004
21
CA
I've seen many articles on WEB explaining how to generate thumbnail images from filesystem and display on web.

I have existing MS Access DB that has many images, and I want to display thumbnail images of those ones on webpage, once clicked display the actual size image.

Has someone used this kind of functionality? Can someone point me to the resource available explaining this?
Thanks in Advance
 
Actually database has images in binary and size in not thumbnail. I was wondering if image from DB can be dynamically shown as thumbnail first and when user wants to see, on clicking db can show actual big image.
 
YOUR WEB FORM ASPX PAGE:
Code:
<asp:DataGrid Runat="server" ID="DataGrid1">
            <Columns>
                    <asp:TemplateColumn >
                        <ItemTemplate>
                            <asp:image  runat="server"  ID="imgMyImage" />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                </Columns>
            </asp:DataGrid>


YOUR WEB FORM CODE BEHIND:
Code:
    Private ImageIndex As Integer = 0
    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
        If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then
            Dim MyImage As System.Web.UI.WebControls.Image = e.Item.FindControl("imgMyImage")
            MyImage.ImageUrl = "ShowImage.aspx?index=" & ImageIndex & "&ImageType=jpeg&targetwidth=75"
            Dim bytes() As Byte = DataBinder.Eval(e.Item.DataItem, "MyDataBaseFieldNameForTheImage")
            Session("ImageBytes" & ImageIndex) = bytes
            ImageIndex = ImageIndex + 1

        End If
    End Sub

YOUR SHOWIMAGE.ASPX PAGE
'Nothing to add the ASPX portion of the page



YOUR SHOWIMAGE.ASPX CODE BEHIND
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim outPutFormat As System.Drawing.Imaging.ImageFormat
        Dim contType As String
        Dim Index As Integer = Request.QueryString("index")
        Dim ImageType As String = Request.QueryString("imagetype")
        Dim TargetWidth As Integer = 0
        If Not Request.QueryString("targetwidth") = Nothing Then
            TargetWidth = Request.QueryString("targetwidth")
        End If

        Select Case ImageType
            Case "png"
                outPutFormat = System.Drawing.Imaging.ImageFormat.Png
                contType = "image/png"
            Case "jpg"
                outPutFormat = System.Drawing.Imaging.ImageFormat.Jpeg
                contType = "image/jpeg"
            Case "gif"
                outPutFormat = System.Drawing.Imaging.ImageFormat.Gif
                contType = "image/gif"

        End Select
        Dim bytes() As Byte = Session("ImageBytes" & Index)
        Session("ImageBytes" & Index) = Nothing
        Dim stmMemory As IO.MemoryStream = New IO.MemoryStream(bytes)


        If TargetWidth > 0 Then
            'Resize
            Dim imgThumb As System.Drawing.Image
            Dim bm_source As New Bitmap(stmMemory)
            Dim scale_factor As Double = TargetWidth / bm_source.Width
            Dim myCallback As System.Drawing.Image.GetThumbnailImageAbort
            Dim myPtr As IntPtr
            imgThumb = bm_source.GetThumbnailImage(CInt(bm_source.Width * scale_factor), CInt(bm_source.Height * scale_factor), myCallback, myPtr)
            bm_source.Dispose()
            stmMemory = New IO.MemoryStream
            imgThumb.Save(stmMemory, outPutFormat)
imgThumb.Dispose()


        End If


        Response.Clear()
        Response.ContentType = contType
        stmMemory.WriteTo(Response.OutputStream)
        Response.End()
    End Sub
 
Thanks a lot for your time and help. I will try this one and let you know. Appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top