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