稍作修改的版本:
public void createThumbnails(string sourceDir)
{
//Process the list of files found in the directory.
string [] fileEntries = Directory.GetFiles(sourceDir);
foreach(string fileName in fileEntries)
{
//Do resizing here.
myimg = System.Drawing.Image.FromFile(fileName);
myimg = myimg.GetThumbnailImage(154, 94, Nothing, IntPtr.Zero);
myimg.Save(Server.MapPath("../Content/") + "Thumb_" + fileName, myimg.RawFormat);
}
}
像这样调用:
createThumbnails("C:\Path\To\Images");
*编辑:使用转换器工具的 VB.NET 等效项:
Public Sub createThumbnails(ByVal sourceDir As String)
Dim fileEntries As String() = Directory.GetFiles(sourceDir)
For Each fileName As String In fileEntries
myimg = System.Drawing.Image.FromFile(fileName)
myimg = myimg.GetThumbnailImage(154, 94, [Nothing], IntPtr.Zero)
myimg.Save((Server.MapPath("../Content/") & "Thumb_") + fileName, myimg.RawFormat)
Next
End Sub