Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,082 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,797 people online right now. Registration is fast and FREE... Join Now!




showing image by double clicking

 
Reply to this topicStart new topic

showing image by double clicking

aamir_mustafa2007@msn.com
20 Apr, 2008 - 03:39 AM
Post #1

New D.I.C Head
*

Joined: 3 Jul, 2007
Posts: 18


My Contributions
for so many days i m trying to solve this problem but didn't succeeded yet bcoz i have not so knowledge of vb.net
i want to show a picture to an other form, lets say it is Form2.
actually my application gets images from data base and then shows those images as thumbnail.
now i want that when double click on a thumbnail it should display that image on form2 extracting image from data base but i don't know how to do that
i m using list view to show thumbnail
this code tries to show this method on picture box of form2, i don't know right or wrong
CODE

Private Sub ShowImage(ByVal bmp As Image)
        FotoInstance.PictureBox1.Width = 150
        FotoInstance.PictureBox1.Height = 115
        FotoInstance.PictureBox1.Image = New Bitmap(bmp)
        FotoInstance.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    End Sub

this code tries to extract the image from data base
CODE

Private Sub GetImage(ByVal item As ListViewItem)

        If SqlConn.State = ConnectionState.Closed Then
            SqlConn.Open()
        End If
        ' Just to be sure make sure it was opened
        If SqlConn.State = ConnectionState.Open Then
            ' Create the stored proc command to retrieve the records
            Dim strCmd As String = [String].Format("SELECT photo FROM Photos WHERE id = {0}", item)
            Dim cmd As New SqlCommand(strCmd, SqlConn)
            cmd.CommandType = CommandType.StoredProcedure
            ' Now execute the command
            Dim sqlPhotoAlbum As SqlDataReader = cmd.ExecuteReader()
            Dim nAlbumID As Integer = 0
            ' Keep track of the current album
            Dim nAlbumIndex As Integer = -1
            ' Keep track of the tree index
            ' Keep reading all the records returned

            Dim imgList As New ImageList
            While (sqlPhotoAlbum.Read())
                'Dim node As TreeNode = Nothing
                'Populate all images
                Dim data As Byte() = CType(sqlPhotoAlbum("photo"), Byte())
                Dim ms As New System.IO.MemoryStream(data, 0, data.Length)
                Dim photo As Image = Image.FromStream(ms) ''

                ShowImage(New Bitmap(ms))

            End While
            sqlPhotoAlbum.Close()
        End If
    End Sub

this code tries to show the image invoking double click event of list view
CODE

Private Sub thumbList_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles thumbList.DoubleClick
        Try
            Dim item As ListViewItem = thumbList.GetItemAt(e.ToString, e.ToString)
            
            GetImage(item)
        Catch ex As Exception

        End Try

    End Sub


these are few methods
CODE

Private Function MatchPhotoIndex(ByVal nID As Integer, ByVal photo As String) As Integer
        Dim node As TreeNode = treeAlbum.Nodes(nID)
        Dim i As Integer
        Dim childNode As TreeNode
        For Each childNode In node.Nodes
            If childNode.Text = photo Then
                For i = 0 To treeAlbum.ImageList.Images.Count - 1
                    If treeAlbum.ImageList.Images.Keys(i) = photo Then
                        childNode.ImageIndex = i
                        Exit For
                    End If
                Next
                Exit For
            End If
        Next
    End Function


CODE

    Private Sub PopulateListView()
        If SqlConn.State = ConnectionState.Closed Then
            SqlConn.Open()
        End If
        ' Just to be sure make sure it was opened
        If SqlConn.State = ConnectionState.Open Then
            ' Create the stored proc command to retrieve the records
            Dim sqlCmd As New SqlCommand("sp_GetPhotoAlbums", SqlConn)
            sqlCmd.CommandType = CommandType.StoredProcedure
            ' Now execute the command
            Dim sqlPhotoAlbum As SqlDataReader = sqlCmd.ExecuteReader()
            Dim nAlbumID As Integer = 0
            ' Keep track of the current album
            Dim nAlbumIndex As Integer = -1
            ' Keep track of the tree index
            ' Keep reading all the records returned
            Dim imgList As New ImageList()
            'Dim array As New ArrayList()
            While (sqlPhotoAlbum.Read())
                'Dim node As TreeNode = Nothing
                'Populate all images
                Dim data As Byte() = CType(sqlPhotoAlbum("photo"), Byte())
                Dim ms As New System.IO.MemoryStream(data, 0, data.Length)
                Dim photo As Image = Image.FromStream(ms) ''
                imgList.Images.Add(sqlPhotoAlbum("Photo").ToString(), photo)
                If thmbNailWidth <> 0 AndAlso thmbNailHeight <> 0 Then
                    'Set Thumbnail size
                    imgList.ImageSize = New Size(thmbNailWidth, thmbNailHeight)
                Else
                    'Default size
                    thmbNailWidth = 100
                    thmbNailHeight = 90
                    imgList.ImageSize = New Size(thmbNailWidth, thmbNailHeight)
                End If
                'Set best color depth for Thumbnail
                imgList.ColorDepth = ColorDepth.Depth32Bit
                thumbList.LargeImageList = imgList
            End While
            sqlPhotoAlbum.Close()
        End If
    End Sub


CODE

    Private Sub ShowThumbnail(ByVal album As String)
        If SqlConn.State = ConnectionState.Closed Then
            SqlConn.Open()
        End If
        ' Just to be sure make sure it was opened
        If SqlConn.State = ConnectionState.Open Then
            Dim sqlCmd As New SqlCommand("sp_GetPhotoAlbums", SqlConn)
            Dim sqlMatchPhoto As SqlDataReader = sqlCmd.ExecuteReader()

            thumbList.Items.Clear()
            While (sqlMatchPhoto.Read())
                If (sqlMatchPhoto("Album").ToString() = album) Then
                    Dim i As Integer, imgIndex As Integer
                    'Get Index of Photo in Image List
                    For i = 0 To thumbList.LargeImageList.Images.Count - 1
                        If thumbList.LargeImageList.Images.Keys(i) = sqlMatchPhoto("Photo").ToString() Then
                            imgIndex = i
                            Exit For
                        End If
                    Next
                    thumbList.Items.Add(sqlMatchPhoto("Photo").ToString(), imgIndex)
                End If
            End While
            sqlMatchPhoto.Close()
        End If
    End Sub



plz kindly help me


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:35PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month