WinForm下批量处理图片9张以上报内存错误
如题 相关代码
Dim dirName As String = DirListBox1.Path.ToString '取得文件夹路径
If Directory.Exists(dirName) Then
Dim arrFile() As String
Dim i As Int32
arrFile = Directory.GetFiles(dirName)
For i = 0 To UBound(arrFile) - 1 '开始处理所有文件
'没有水印
Dim image, aNewImage As System.Drawing.Image
Dim width, height, newwidth, newheight As Integer
Dim callb As System.Drawing.Image.GetThumbnailImageAbort
'生成缩略图
image = System.Drawing.Image.FromFile((arrFile(i) + ControlChars.NewLine))
width = image.Width
height = image.Height
If width > height Then
newwidth = TextBox1.Text
newheight = image.Height / image.Width * newwidth
Else
newheight = TextBox2.Text
newwidth = image.Width / image.Height * newheight
End If
aNewImage = image.GetThumbnailImage(newwidth, newheight, callb, New System.IntPtr)
aNewImage.Save((DirListBox2.Path.ToString & "/ " & i & ".jpg "))
image.Dispose()
Next
MsgBox( "图片处理成功! ")
Else
MsgBox( "错误! ")
End If
[解决办法]
aNewImage没销掉
[解决办法]
aNewImage.Dispose();
加上
Application.DoEvent();