SizePic 说明:可以用于WEB网站图片缩略图的批量处理[4]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

       Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.PictureBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.Text = "SizePic    wgscd @ 2005"
        CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.NumericUpDown2, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim SizeW As Integer = 70
    Dim SizeH As Integer = 70
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SizeW = NumericUpDown1.Value
        SizeH = NumericUpDown2.Value
        doJob()
    End Sub
    Sub doJob()

        Dim dir As New IO.DirectoryInfo(Me.TextBox1.Text)

        Dim img As Bitmap
        Dim f As IO.FileInfo

        Dim i As Integer
        '  Me.ProgressBar1.Maximum = dir.GetFiles.Length

        '  MsgBox("一共有" & dir.GetFiles.Length & "个文件,请稍等处理。。。")

        For Each f In dir.GetFiles


            If f.Extension.ToLower = ".jpg" Or f.Extension.ToLower = ".bmp" Or f.Extension.ToLower = ".png" Or f.Extension.ToLower = ".gif" Then

                img = Image.FromFile(f.FullName)
                Dim w, h As Integer

                w = img.Width
                h = img.Height

                If w > SizeW AndAlso h > SizeH Then


                    If w / h > 1 Then '判断宽和高比例,如果搞高比宽小

                        Dim imgok As New Bitmap(img, (w / h) * SizeW, SizeH) '以高为基本


                        Dim okW, okH, a, g, b As Integer
                        Dim okColor As Color

                        okW = imgok.Width - 1

                        okH = imgok.Height - 1

                        Dim newBitmp As New Bitmap(SizeW, SizeH)
                        Try

本文关键:SizePic 说明:可以用于WEB网站图片缩略图的批量处理
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top