creating thumbnails from .jpg

J

James

Hi, I'm a newbie to VB.NET and I am trying to create thumbnails from .jpg
files (my travel pictures) to
post on a website. I want to create an executable that I can put in a
directory containing my jpg images which will create the thumbnails with a
"-t.jpg" extenstion. I found this code below which will create a thumbnail
from a specified file, "randomphoto.jpg".

Sub Thumbnail()
Dim myCallback As System.Drawing.Image.GetThumbnailImageAbort
Dim myPtr As IntPtr
Dim myPic As New Bitmap("E:\randomphoto.jpg")
Dim myThumb As System.Drawing.Image = myPic.GetThumbnailImage(100, 100,
myCallback, myPtr)
myThumb.Save("E:\mythumb.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
End Sub

How can I alter this code to pick out any .jpg file in the current directory
and create a thumbnail. Do I use a looping structure to read each file and
run the above module? Any help in pointing me in the right direction
appreciated.
James
 
H

Herfried K. Wagner [MVP]

* "James said:
Hi, I'm a newbie to VB.NET and I am trying to create thumbnails from .jpg
files (my travel pictures) to
post on a website. I want to create an executable that I can put in a
directory containing my jpg images which will create the thumbnails with a
"-t.jpg" extenstion. I found this code below which will create a thumbnail
from a specified file, "randomphoto.jpg".

Sub Thumbnail()
Dim myCallback As System.Drawing.Image.GetThumbnailImageAbort
Dim myPtr As IntPtr
Dim myPic As New Bitmap("E:\randomphoto.jpg")
Dim myThumb As System.Drawing.Image = myPic.GetThumbnailImage(100, 100,
myCallback, myPtr)
myThumb.Save("E:\mythumb.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
End Sub

How can I alter this code to pick out any .jpg file in the current directory
and create a thumbnail. Do I use a looping structure to read each file and
run the above module? Any help in pointing me in the right direction
appreciated.

\\\
Dim s As String
For Each s In System.IO.Directory.GetFiles("C:\foo")
...
Next s
///
 
F

Frank Eller [MVP]

Hi James,
Hi, I'm a newbie to VB.NET and I am trying to create thumbnails from
.jpg files (my travel pictures) to
post on a website. I want to create an executable that I can put in a
directory containing my jpg images which will create the thumbnails
with a "-t.jpg" extenstion. I found this code below which will
create a thumbnail from a specified file, "randomphoto.jpg".

Sub Thumbnail()
Dim myCallback As System.Drawing.Image.GetThumbnailImageAbort
Dim myPtr As IntPtr
Dim myPic As New Bitmap("E:\randomphoto.jpg")
Dim myThumb As System.Drawing.Image =
myPic.GetThumbnailImage(100, 100, myCallback, myPtr)
myThumb.Save("E:\mythumb.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg) End Sub

How can I alter this code to pick out any .jpg file in the current
directory and create a thumbnail. Do I use a looping structure to
read each file and run the above module? Any help in pointing me in
the right direction appreciated.

Check the GetFiles()-method from the DirectoryInfo-Class, which gives you
all the files in a directory as FileInfo-Objects. You can use those in a
loop to create your thumbnails.

Regards,

Frank Eller
www.frankeller.de
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top