|
-
Dec 11th, 2006, 08:23 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] load first pic from file
hi im trying to load the first jpg from a folder and here's my code but I m getting error on the last line. Can someone pls correct me? ths
Dim Imagespath() As String = System.IO.Directory.GetFiles("C:\Underline_pics" & ("*.jpg"))
' Dim imagesindexes as New List(Of Integer)
frontpic.Image = Image.FromFile(Imagespath.IndexOf(0))
-
Dec 11th, 2006, 08:29 AM
#2
Re: load first pic from file
The IndexOf method searches through an array to find the index of the thing you are searching for, which in this case is a 0. You have missed some parameters in the IndexOf method, causing some errors to show. Altough that doesnt matter now because I think that you just want to show the first picture in the array, and that would simply be:
VB Code:
Image.FromFile(Imagespath(0))
EDIT: Correct me if im wrong, but is Underline_pics a folder that contains the pictures? In that case you should provide that as first argument of the getfiles method, and the filetype to retrieve as second argument. Like so:
VB Code:
Dim Imagespath() As String = System.IO.Directory.GetFiles("C:\Underline_pics", "*.jpg")
Last edited by Atheist; Dec 11th, 2006 at 08:33 AM.
-
Dec 11th, 2006, 08:46 AM
#3
Re: load first pic from file
Did this work for you? In that case please mark thread as resolved
-
Dec 11th, 2006, 08:53 AM
#4
Thread Starter
Frenzied Member
Re: load first pic from file
yes, your're right.
Now I need to load the 2,3,4,5 with a button click, how can I use. any examples ?
-
Dec 11th, 2006, 09:28 AM
#5
Re: load first pic from file
Do you mean you want to change the image in the current picturebox with each button click?
VB Code:
Dim currentPic As Integer = 0 'Set variable
Dim Imagespath() As String = System.IO.Directory.GetFiles("C:\Underline_pics", "*.jpg") 'Load images into array
'Load 1st pic on form_load
frontpic.Image = Image.FromFile(Imagespath(currentPic))
Then under the button click you simply update the variable and load the next picture:
VB Code:
currentPic += 1 'Update
frontpic.Image = Nothing
frontpic.Image = Image.FromFile(Imagespath(currentPic)) 'Load next pic
If you have 5 more pictureboxes then you would simply add 5 lines of code adding them as you have done except with an index value of 1, 2, 3, etc...
-
Dec 12th, 2006, 03:38 AM
#6
Thread Starter
Frenzied Member
Re: [RESOLVED] load first pic from file
hi stimbo,
many thanks works fine now
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|