Results 1 to 6 of 6

Thread: [RESOLVED] load first pic from file

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Resolved [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))

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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:
    1. 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:
    1. Dim Imagespath() As String = System.IO.Directory.GetFiles("C:\Underline_pics", "*.jpg")
    Last edited by Atheist; Dec 11th, 2006 at 08:33 AM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: load first pic from file

    Did this work for you? In that case please mark thread as resolved
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    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 ?

  5. #5
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    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:
    1. Dim currentPic As Integer = 0 'Set variable
    2. Dim Imagespath() As String = System.IO.Directory.GetFiles("C:\Underline_pics", "*.jpg")   'Load images into array
    3.  
    4. 'Load 1st pic on form_load
    5. frontpic.Image = Image.FromFile(Imagespath(currentPic))

    Then under the button click you simply update the variable and load the next picture:

    VB Code:
    1. currentPic += 1 'Update
    2. frontpic.Image = Nothing
    3. 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...
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    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
  •  



Click Here to Expand Forum to Full Width