Results 1 to 7 of 7

Thread: [ASK]Photo Viewer

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2015
    Posts
    17

    Question [ASK]Photo Viewer

    hello everyone , anybody tried to create a photo viewer with next and previous button feature?? me and my friends tried to build it , but we're confused , please reply my post we need your answer and thx before ^^

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,901

    Re: [ASK]Photo Viewer

    What is the part you are having problems with?
    - getting a list of images from a directory
    - showing an image on the screen
    - previous/next button

    And are you really using Visual Basic 6?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2015
    Posts
    17

    Re: [ASK]Photo Viewer

    Quote Originally Posted by Arnoutdv View Post
    What is the part you are having problems with?
    - getting a list of images from a directory
    - showing an image on the screen
    - previous/next button

    And are you really using Visual Basic 6?
    well we're confused on the next and previous button ._. and we use VS 2010 I think.. sorry I didn't give any detail of it , because I typed this thread on smartphone

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [ASK]Photo Viewer

    Thread moved to the VB.Net forum.

    You need to provide more information to get any help. Where are the images stored, how are you displaying them? Please show us what you have done already.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: [ASK] VS 2015 , How to create a photoviewer with next and previous button feature

    1. How are you trying to "open" the files? If you want to view an image then it seems logical to use a PictureBox. If you want to load an image file into a PictureBox then you should call the Load method and pass the path.

    2. Call the Directory.GetFiles method to get an array of file paths for a folder. If you want multiple file types then you'll have to call GetFiles multiple times and then combine the arrays into a single list. Store an index for that list in an Integer variable, starting at zero. The Next button will increment that variable and then load the file at the new index and the Previous button will decrement the index and load. You'll need to decide whether to load the file list each time to allow for changes or to just use the initial list each time. If you choose the latter then you might want to check that the file still exists before trying to load it. If you don't refresh the list each time you navigate then a separate Refresh button might be a good idea.

  6. #6
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,902

    Re: [ASK]Photo Viewer

    I merged your threads because they appear to be asking exactly the same thing. If you've got an existing question and want to take it further simply post into your existing thread.

    Thanks
    FD
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  7. #7
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [ASK]Photo Viewer

    By coincidence, I have just been working on a general purpose image browser (for drawings, photos, scans etc.). And it has Back and Forward buttons which I hope will help you solve your problem.

    The first Sub allows the user to select a specific image, but it also builds a list of all the images in the chosen folder (using the same method as recommended by JMcIlhinney).

    The Back and Forward button subs work (respectively) by decrementing or incrementing an index which is used to pick an Image from the list. Note the use of the MOD operator to allow continuous cycling back or forth through the folder. The last sub, GetImage, loads the indexed image into the display control (PictureBox1). I haven't debugged it exhaustively but my version (which includes more code for showing data about the image) seems to be working fine.
    Code:
        Private imageFiles As List(Of String)
        Private imageIndex As Integer
    
        'Show an Open File Dialog to get a list of image files:
        Private Sub Button7_Click_1(sender As Object, e As EventArgs) Handles Button7.Click
            Using ofd As New OpenFileDialog With {.Filter = "Image Files|*.png; *.jpg; *.jpeg; *.gif; *.bmp; *.tif; *.tiff|All Files|*.*"}
                If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                    Dim imageFolder As String = IO.Path.GetDirectoryName(ofd.FileName)        
                    imageFiles = New List(Of String)
                    Dim extensions As String() = {"*.png", "*.jpg", "*.jpeg", "*.gif", "*.bmp", "*.tif", "*.tiff"}
                    For Each ext As String In extensions
                        imageFiles.AddRange(IO.Directory.GetFiles(imageFolder, ext.ToLower, IO.SearchOption.TopDirectoryOnly))
                    Next
                    imageFiles.Sort() 'store the images in alphabetic order of filename
                    imageIndex = imageFiles.IndexOf(ofd.FileName) 'get the index of the selected image
                    GetImage()
                End If
            End Using
        End Sub
    
        'Browse forward through image list:
        Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
           If ImageFiles.Count>0
               imageIndex = (imageFiles.Count + imageIndex - 1) Mod imageFiles.Count
               GetImage()
           End If
        End Sub
    
        'Browse back through image list:
        Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
          If ImageFiles.Count>0 Then  
              imageIndex = (imageIndex + 1) Mod imageFiles.Count
              GetImage()
          End If
       End Sub
    
        'Display the image
        Private Sub GetImage()
            Try
                PictureBox1.Image = Image.FromFile(imageFiles(imageIndex))
            Catch
                'show the name of the faulty file:
                Dim imgpath As String = imageFiles(imageIndex)
                MessageBox.Show("Error reading image from file " & IO.Path.GetFileName(imgpath))
            End Try
        End Sub
    BB

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