1
我正在嘗試創建一個程序來檢查是否有人要進入歡樂時光。如果不是,則列出那些不是的人,並將他們的照片放在他們的名字旁邊。從文件中獲取圖像並將它們添加到陣列
我能夠實現所有,但本地獲取圖像,並將它們存儲在一個數組(它將被添加到pictureArray(i))。
(你可以看到註釋掉的部分在哪裏,我試圖讓圖像...)
任何想法?
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
你能否詳細說明一下?這不適合我。你能解釋一下如何將每個JPG文件從一個文件夾放到Image數組中?謝謝 – Growler 2012-01-16 04:29:37
@Growler:那麼你應該解釋什麼是不工作,你有任何錯誤?我已經向您展示瞭如何以List(Of FileInfo)的形式獲取文件夾中的所有jpg文件。 [List(Of T)](http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx)比Array更好,它甚至比[更好的ArrayList](http:// blog.drorhelper.com/2008/10/why-should-i-use-list-and-not-arraylist.html)。如果你堅持使用數組,你可以簡單地調用'dir.GetFiles(「*。jpg」,IO.SearchOption.AllDirectories).ToArray'。 – 2012-01-16 08:02:51
@Growler:查看[FileInfo-Class](http://msdn.microsoft.com/zh-cn/library/system.io.fileinfo.aspx)獲取更多信息。例如,您需要調用[FileInfo.Name](http://msdn.microsoft.com/en-us/library/system.io.fileinfo.name)來獲取圖像名稱(文件名無路徑)或[FileInfo.FullName](http://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.fullname.aspx)獲取完整路徑。如果這沒有幫助,你應該展示你的嘗試。 – 2012-01-16 08:05:26