递归函数如下:Dim width As Integer = args(0) '模板宽度
Dim height As Integer = args(1) '模板高度
Dim ImagePath As String = args(2) '图片文件
Dim iSource As Image = getimage(ImagePath)
Dim ob As Bitmap = new Bitmap(width , height )
Dim g As Graphics = Graphics.FromImage(ob)
g.Clear(Color.WhiteSmoke)
g.DrawImage(iSource, new Rectangle(0,0, width , height ), 0, 0, iSource.Width, iSource.Height, GraphicsUnit.Pixel)
Dim dFile As String = "D:\test01.JPG"
ob.Save(dFile)
Application.DoEvents()
Dim Info As new FileInfo(dFile)
Dim len As Integer = info.Length
width = width - 100
height = height - 100
If len < 204800 '判断图片大小是否大于200KB
Return True '返回不了这个TRUE
Else
Vars("RecursiveCount") += 1 '测试记录一下递归次数
Functions.Execute("ImageCompress",width,height ,ImagePath) '递归
End If
iSource.Dispose()
ob.Dispose()
g.Dispose()
附上例子: