|
-
Jul 17th, 2008, 12:48 PM
#1
Thread Starter
Hyperactive Member
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
-
Jul 17th, 2008, 01:14 PM
#2
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
-
Jul 17th, 2008, 06:43 PM
#3
Thread Starter
Hyperactive Member
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?
-
Jul 17th, 2008, 09:56 PM
#4
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.
-
Jul 17th, 2008, 10:52 PM
#5
Fanatic Member
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 ?
-
Jul 18th, 2008, 07:51 AM
#6
Re: images from folder
What do you mean exactly? Thumbnails of the slides?
-
Jul 18th, 2008, 08:13 AM
#7
Fanatic Member
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.
-
Jul 18th, 2008, 06:18 PM
#8
Thread Starter
Hyperactive Member
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?
-
Sep 25th, 2008, 04:46 AM
#9
Lively Member
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
-
Sep 25th, 2008, 04:53 AM
#10
Re: images from folder
In my opinion loading thumbnails in ListView control is a better choice. In that way you can select single or multiple images, navigate between images with keyboard using arrow keys.
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
|