Foxtable(狐表)用户栏目专家坐堂 → 压缩图片后系统卡顿


  共有2278人关注过本帖树形打印复制链接

主题:压缩图片后系统卡顿

帅哥,在线噢!
刘林
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1942 积分:14913 威望:0 精华:0 注册:2016/4/28 9:58:00
压缩图片后系统卡顿  发帖心情 Post By:2019/11/3 21:04:00 [只看该作者]

Dim ftp1 As New FtpClient
ftp1.Host=""
ftp1.Account = ""
ftp1.Password = ""
Dim r As Row = Tables("人员花名_table1").Current
Dim t11 As String = e.Form.Controls("textbox11").text
If T11>""
    If ValidPIN(r("身份证号码"))= False
        messagebox.show("请正确填写身份证号码后才能上传其相片")
        Return
    Else
        Dim ifo As new FileInfo(t11)
        If  Ifo.Length>40960 '大于40k才压缩
            Dim img As image = getimage(t11)
            Dim bmp As new bitmap(img.width, img.height)
            Dim g = graphics.fromimage(bmp)
            g.DrawImage(img, 0, 0, img.Width, img.Height)
            Dim jpgEncoder As ImageCodecInfo
            Dim codecs() As ImageCodecInfo = ImageCodecInfo.GetImageDecoders
            For Each codec As ImageCodecInfo In codecs
                If (codec.FormatID = ImageFormat.Jpeg.Guid) Then
                    jpgEncoder = codec
                    Exit For
                End If
            Next
            Dim myEncoder As System.Drawing.Imaging.Encoder = System.Drawing.Imaging.Encoder.Quality
            Dim myEncoderParameters As EncoderParameters = New EncoderParameters(1)
            Dim myEncoderParameter As EncoderParameter = New EncoderParameter(myEncoder, 200) ' 质量级别 0 对应于最大压缩,而质量级别 100 对应于最小压缩
            myEncoderParameters.Param(0) = myEncoderParameter
            Dim slt As String =  ifo.path & T11 & ifo.Extension
            bmp.Save(slt,jpgEncoder, myEncoderParameters)
            bmp.dispose
            g.dispose
            Dim img1 As image = getImage(slt)
            Dim bmp1 As bitmap
            If img1.width > 400 Then
                If 400 * (img1.height / img1.width) > 300 Then
                    bmp1 = new bitmap(img1, 400*(300/(400*(img1.height/img1.width))), 300)
                Else
                    bmp1 = new bitmap(img1, 300, 300 * (img1.height / img1.width))
                End If
                bmp1.save(slt, ImageFormat.Jpeg)
                bmp1.Dispose
            End If
            If ftp1.Upload(slt,"\xp\" & FileSys.GetName(T11 & Ifo.extension),True) = True Then
                r("相片")="\xp\" & FileSys.GetName(T11 & Ifo.extension)
                r.save
                '   messagebox.show(ProjectPath & "\RemoteFiles\xp\T11" & Ifo.extension)
                '  bmp1.save(ProjectPath & "RemoteFiles\xp\" & T11 & Ifo.extension)
                e.Form.Controls("textbox11").text=""
                
            Else
                Messagebox.show("上传失败,请重新上传该文件!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
            End If
            
        Else
            'If ftp1.Upload(t11,"\xp\" & FileSys.GetName(T11 & Ifo.extension),True) = True Then
            'r("相片")="\xp\" & FileSys.GetName(T11 & Ifo.extension)
            'r.save
            'e.Form.Controls("textbox11").text=""
            
            If ftp1.Upload(t11,"\xp\" & T11 & Ifo.extension,True) = True Then
                r("相片")="\xp\" & T11 & Ifo.extension
                r.save
                e.Form.Controls("textbox11").text=""
                
            Else
                Messagebox.show("上传失败,请重新上传该文件!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
            End If
        End If
    End If
Else
    messagebox.show("你没打开相片")
End If


老师请问上面的代码是想用打开文件压缩上传并以身份证号命名文件,但只要传两张后,系统就卡,死机,有时会自动关了,我估这种方式是不是占用内存过大或内存溢出,请问该怎么改才行

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107440 积分:546479 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/11/3 21:32:00 [只看该作者]

图片处理本身就很费资源的,特别是大图片.何况还压缩了2次

Dim ftp1 As New FtpClient
ftp1.Host=""
ftp1.Account = ""
ftp1.Password = ""
Dim r As Row = Tables("人员花名_table1").Current
Dim t11 As String = e.Form.Controls("textbox11").text
If T11>""
    If ValidPIN(r("身份证号码"))= False
        messagebox.show("请正确填写身份证号码后才能上传其相片")
        Return
    Else
        Dim ifo As new FileInfo(t11)
        If  Ifo.Length>40960 '大于40k才压缩
            Dim img1 As image = getImage(t11)
            Dim bmp1 As bitmap
            If img1.width > 400 Then
                If 400 * (img1.height / img1.width) > 300 Then
                    bmp1 = new bitmap(img1, 400*(300/(400*(img1.height/img1.width))), 300)
                Else
                    bmp1 = new bitmap(img1, 300, 300 * (img1.height / img1.width))
                End If
                bmp1.save(slt, img.RawFormat)
                bmp1.Dispose
            End If
            If ftp1.Upload(slt,"\xp\" & FileSys.GetName(T11 & Ifo.extension),True) = True Then
                r("相片")="\xp\" & FileSys.GetName(T11 & Ifo.extension)
                r.save
                '   messagebox.show(ProjectPath & "\RemoteFiles\xp\T11" & Ifo.extension)
                '  bmp1.save(ProjectPath & "RemoteFiles\xp\" & T11 & Ifo.extension)
                e.Form.Controls("textbox11").text=""
                
            Else
                Messagebox.show("上传失败,请重新上传该文件!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
            End If
            
        Else
            'If ftp1.Upload(t11,"\xp\" & FileSys.GetName(T11 & Ifo.extension),True) = True Then
            'r("相片")="\xp\" & FileSys.GetName(T11 & Ifo.extension)
            'r.save
            'e.Form.Controls("textbox11").text=""
            
            If ftp1.Upload(t11,"\xp\" & T11 & Ifo.extension,True) = True Then
                r("相片")="\xp\" & T11 & Ifo.extension
                r.save
                e.Form.Controls("textbox11").text=""
                
            Else
                Messagebox.show("上传失败,请重新上传该文件!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
            End If
        End If
    End If
Else
    messagebox.show("你没打开相片")
End If

 回到顶部