I am making a tool that transforms a photo upload by the user into bytes array then compares those bytes with the photos in the database
I was able to make the code work but when in the end it detected something the same or similar then it shows the one used in picturebox1
and the one found in the database that in this case is inserted in a listbox
when the program does load .
When it finishes the operation after finding a match it gives me error.
My error is:
Out Of Memory is in function timer1
My code is:
Public Class Form3
Dim totalbytes As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Using fo As New OpenFileDialog
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
Dim byteArea As Byte()
byteArea = br.ReadBytes(CInt(fs.Length))
totalbytes = fs.Length
br.Close()
'just to show the sample without a fileread error
'be aware not to use a dispose or using here
'it gives a GDI+ error as the stream (not the name) is reused.
Dim ms As New IO.MemoryStream(byteArea)
PictureBox1.Image = Image.FromStream(ms)
End If
End Using
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim byteArea As Byte()
Using msX As New IO.MemoryStream
PictureBox1.Image.Save(msX, Imaging.ImageFormat.Bmp)
byteArea = msX.ToArray()
End Using
Using ms2 As New IO.MemoryStream(byteArea)
Me.PictureBox2.Image = Image.FromStream(ms2)
End Using
Me.PictureBox1.Image = Nothing
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim finfo As New IO.DirectoryInfo("C:\flora")
For Each fi In finfo.GetFiles
ListBox1.Items.Add(fi.FullName)
Next
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex + 1
''PictureBox1.Image = Image.FromFile(Me.ListBox1.SelectedItem.ToString())
Dim ffs As New IO.FileStream(ListBox1.SelectedItem, IO.FileMode.Open)
Dim bbr As New IO.BinaryReader(ffs)
Dim byteArea As Byte()
byteArea = bbr.ReadBytes(CInt(ffs.Length))
If ffs.Length = totalbytes Then
Timer1.Stop()
Dim pict2 As String = ListBox1.SelectedItem.ToString
PictureBox2.Image = Image.FromFile(pict2)
MsgBox("Resultados Encontrado " + ListBox1.SelectedItem)
End If
''MessageBox.Show(fs.Length)
bbr.Close()
'just to show the sample without a fileread error
'be aware not to use a dispose or using here
'it gives a GDI+ error as the stream (not the name) is reused.
Dim ms As New IO.MemoryStream(byteArea)
PictureBox1.Image = Image.FromStream(ms)
''MessageBox.Show(ms.ReadByte)
ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex + 1
End Sub
End Class