首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

WinForm下批量处理图片9张以上报内存异常

2012-01-26 
WinForm下批量处理图片9张以上报内存错误如题相关代码DimdirNameAsStringDirListBox1.Path.ToString取得

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();

热点排行