批量图像尺寸调整器
批量调整大小或一次调整多个图像,只需拖放文件并指定高度和宽度
引言
批量图像调整大小工具会将所有选定的图像调整为文本框中指定的特定大小。要一次调整多个图像,只需将文件拖放到左侧框中(左侧框仅接受图像文件),指定要调整图像的高度和宽度,然后单击“调整大小”按钮。然后,它将在右侧框中显示所有调整大小后的图像。右侧框中选中的图像已成功调整大小,未选中的图像由于某种错误而未成功调整大小。
Using the Code
以下是主要源代码...
以下子程序调整不同格式的图像的大小,并保持其原始格式。
Private Sub BatchImageResizerfun(ByVal strr As String)
Dim bm As New Bitmap(strr)
Dim i As Integer
Dim str11 As String = Mid(strr, Len(strr) - 2, 3) 'Stores the format
'of the image i.e. png, jpg
Dim bmname As String = ""
Dim c As Char = Nothing
For i = 4 To Len(strr) 'stores filename
c = Mid(strr, Len(strr) - i, 1)
If c = Char.Parse("\") Then
Exit For
End If
bmname = bmname + c
Next
bmname = mypicturefolder & "\" & StrReverse(bmname)
Dim width As Integer = Integer.Parse(TextBox2.Text) 'image width.
Dim height As Integer = Integer.Parse(TextBox1.Text) 'image height
Dim thumb As New Bitmap(width, height)
Dim g As Graphics = Graphics.FromImage(thumb)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(bm, New Rectangle(0, 0, width, height), _
New Rectangle(0, 0, bm.Width, bm.Height), GraphicsUnit.Pixel)
g.Dispose()
Try
Select Case Strings.LCase(str11) 'saves the file to their
'corresponding format after resize
Case ""
Exit Sub
Case "bmp"
thumb.Save(bmname & ".bmp", Imaging.ImageFormat.Bmp)
Case "jpg"
thumb.Save(bmname & ".jpg", Imaging.ImageFormat.Jpeg)
Case "gif"
thumb.Save(bmname & ".gif", Imaging.ImageFormat.Gif)
Case "ico"
thumb.Save(bmname & ".ico", Imaging.ImageFormat.Icon)
Case "png"
thumb.Save(bmname & ".png", Imaging.ImageFormat.Png)
Case "tiff"
thumb.Save(bmname & ".tiff", Imaging.ImageFormat.Tiff)
Case "wmf"
thumb.Save(bmname & ".wmf", Imaging.ImageFormat.Wmf)
End Select
CheckedListBox1.Items.Add(bmname & "." & str11, True) 'file resized
'successfully
Catch ex As Exception
CheckedListBox1.Items.Add(bmname & "." & str11, False) 'file resizing
'unsuccessful
End Try
bm.Dispose()
thumb.Dispose()
End Sub
当从资源管理器中将图像拖放到左侧框时,它会检查以下内容
- 是否为图像文件。如果不是,则不要添加到列表中。
- 如果图像文件已添加到列表中,则不要再次添加。
要删除要调整大小的图片,请选择文件并右键单击以从列表中删除。
要调整图片大小,请指定要调整的宽度和高度,然后单击“调整大小”按钮。它会调整图片大小并打开存储图片的目录。
下图显示了它的工作方式