Results 1 to 10 of 10

Thread: images from folder

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    366

    images from folder

    Hi I want a little program that looks at the folder specified in the code then loads into as many picture boxes as it takes all the images, as thumbnails. I have a program that turns an image into a thumbnail, but a) please can you help me check how many images there are, and grab their names - to turn into thumbnails, and b, add the picture boxes to go with them.

    The code i have is below. one button opens dialog to the picture to make into a thumbnail, the other turns it into a tumbnail - but it does it using the form.paint commnad, i want it in picture boxes.

    please can someone help me modify this?

    thnkas

    Code:
    Public Class Form1
    
        Private Sub btnopen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnopen.Click
            If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                txtfilenm.Text = OpenFileDialog1.FileName
            End If
        End Sub
        ' Declare a class level variable
    
        Dim imgThumb As Image = Nothing
        Private Sub btngeneratethumbnail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngeneratethumbnail.Click
            Try
                Dim image As Image = Nothing
                ' Check if textbox has a value
                If txtfilenm.Text <> String.Empty Then
                    image = image.FromFile(txtfilenm.Text)
                End If
                ' Check if image exists
                If Not image Is Nothing Then
                    imgThumb = image.GetThumbnailImage(100, 100, Nothing, New IntPtr())
                    Me.Refresh()
                End If
            Catch
                MessageBox.Show("An error occured")
            End Try
        End Sub
    
      
    
        Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            If Not imgThumb Is Nothing Then
                e.Graphics.DrawImage(imgThumb, 30, 20, imgThumb.Width, imgThumb.Height)
            End If
        End Sub
    End Class

  2. #2
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: images from folder

    Put a FlowLayoutPanel on your form so that you don't have to worry about positioning, and then use this:

    Code:
    If Not image Is Nothing Then
        Dim pbo As New PictureBox()
        With pbo
            .Size = New Size(100, 100)
            .SizeMode = PictureBoxSizeMode.Stretch
            .Image = image.GetThumbnailImage(100, 100, Nothing, New IntPtr())
        End With
        FlowLayoutPanel1.Controls.Add(pbo)
    End If

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    366

    Re: images from folder

    it doesnt work because . stretch doesnt exist:
    Code:
    Private Sub btngeneratethumbnail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngeneratethumbnail.Click
            Try
                Dim image As Image = Nothing
                ' Check if textbox has a value
                If txtfilenm.Text <> String.Empty Then
                    image = image.FromFile(txtfilenm.Text)
                End If
                ' Check if image exists
                If Not image Is Nothing Then
                    Dim pbo As New PictureBox()
                    With pbo
                        .Size = New Size(100, 100)
                        .SizeMode = PictureBoxSizeMode.Stretch
                        .Image = image.GetThumbnailImage(100, 100, Nothing, New IntPtr())
                    End With
                    FlowLayoutPanel1.Controls.Add(pbo)
                End If
            Catch
                MessageBox.Show("An error occured")
            End Try
        End Sub
    will that solve my prblem?

  4. #4
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: images from folder

    My apologies, that shouldn't be .Stretch, it should be .StretchImage. I was just typing directly into the site because I didn't have access to VS.

  5. #5
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: images from folder

    Is there any way to get a thumbnail of say powerpoint ppt types. ppt appears fine on explorer. How can I get a thumbnail on a form ?

  6. #6
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: images from folder

    What do you mean exactly? Thumbnails of the slides?

  7. #7
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: images from folder

    Yes, thumbnail of the 1st slide at least. That's what appears on explorer when you see a ppt in a directory.

    If we can get thumbnails of all slides, that's a bonus.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    366

    Re: images from folder

    is there a way i can modify that code above to make a thumbnail of every jpeg in a selected folder?

  9. #9
    Lively Member
    Join Date
    Aug 2008
    Posts
    75

    Re: images from folder

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
                Return
            Else
                Try
                    Dim image As Image = Nothing
                    ' Check if textbox has a value
                    If OpenFileDialog1.FileName <> String.Empty Then
                        image = image.FromFile(OpenFileDialog1.FileName)
                    End If
                    ' Check if image exists
                    If Not image Is Nothing Then
                        If Not image Is Nothing Then
                            Dim pbo As New PictureBox()
                            With pbo
                                .Size = New Size(100, 100)
                                .SizeMode = PictureBoxSizeMode.StretchImage
                                .Image = image.GetThumbnailImage(100, 100, Nothing, New IntPtr())
                            End With
                            FlowLayoutPanel1.Controls.Add(pbo)
                        End If
                    End If
                Catch
                    MessageBox.Show("An error occured")
                End Try
            End If
    just use this code and a loop on the files in the folderbrowserdialog

  10. #10

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