Getting Images From file and Adding them to Array

Growler

Member
Joined
Sep 23, 2010
Messages
13
Programming Experience
Beginner
Hello,

I'm trying to create a program that checks if someone is going to Happy Hour, if not, it lists those who aren't, and puts their picture next to their name.
I'm able to achieve all but get the images locally and store them in an array (which would be added to pictureArray(i))
You can see the commented out sections are where I've tried to get the images...

Any ideas? Much appreciated.

ITLP Happy Hour App Show.jpg

VB.NET:
Public Class Form1
    Dim ITLPList() As String = {"Name 1", "Name 2", "Name 3", "Name 4", "Name 5", "Name 6"}
    '  Dim imageList As New ImageList
    ' Dim fileSteam As New System.IO.FileStream(sFileName, System.IO.FileMode.Open)
    ' Dim img As Image
    ' Dim sFileName As String = "C:\Users\turcotd\Desktop\ITLPers\itlp1.jpg"

    Dim itlpTally() As String
    Dim labelArray(5) As Label
    Dim pictureArray(5) As PictureBox

    Dim intTally As Integer
    Dim i As Integer = 0

    Public itlpIndex As Integer = 0

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        itlpName.Text = ITLPList(0)
        labelArray(0) = lblPerson0
        labelArray(1) = lblPerson1
        labelArray(2) = lblPerson2
        labelArray(3) = lblPerson3
        labelArray(4) = lblPerson4

        pictureArray(0) = picITLP0
        pictureArray(1) = picITLP1
        pictureArray(2) = picITLP2
        pictureArray(3) = picITLP3
        pictureArray(4) = picITLP4

    End Sub

    Private Sub btnYes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYes.Click

        If (i < 6) Then
            itlpName.Text = ITLPList(i)
            i = i + 1

        End If
    End Sub

    Private Sub btnNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNo.Click

        If (i < 6) Then
            'Names
            itlpName.Text = ITLPList(i)
            intTally = intTally + 1
            lblTally.Text = intTally
            labelArray(i).Text = ITLPList(i)

            'Images
            '    img = Image.FromStream(fileSteam)
            '   fileSteam.Close()
            '  imageList.Images.Add(img)
            '  pictureArray(i).Image = imageList.Images.Item(0)
            '  img.Dispose()

            ' img = Image.FromFile(sFileName)

            i = i + 1
        End If
        itlpName.Text = ITLPList(i)
    End Sub
End Class
 

Attachments

  • ITLP Happy Hour App Show.jpg
    ITLP Happy Hour App Show.jpg
    30.6 KB · Views: 40
Okay, didn't know about the Load method, thanks!

But, I'd like to load several images in a folder in an array of PictureBoxes.

So, I'm assuming it's something similar to this:

VB.NET:
    Private Sub btnNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNo.Click
        Dim imageArray As New ArrayList()
        Dim dir = New IO.DirectoryInfo("C:\Users\turcotd\Desktop\ITLPers")
        Dim images = dir.GetFiles("*.jpg", IO.SearchOption.AllDirectories).ToList

        If (i < 6) Then
            'Names
            itlpName.Text = ITLPList(i)
            intTally = intTally + 1
            lblTally.Text = intTally
            labelArray(i).Text = ITLPList(i)

            For Each file As IO.FileInfo In images 'for each file in myImages location
                imageArray.Add(file.Name) 'add an image to the Image List
            Next

            pictureArray(i).Load(dir + imageArray(i))

            i = i + 1
        End If
        itlpName.Text = ITLPList(i)
    End Sub
End Class
 
Back
Top