以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  判断文件是否可用  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=183659)

--  作者:fendouww
--  发布时间:2022/11/11 15:28:00
--  判断文件是否可用
                老师,我用以下方式把图片缩小另存为时,有极少情况下Dim img As image = getImage(str)在这一句时会报错,原因是str文件虽然后缀是图片格式,但实际是错误文件,打不开的,我要如何判断此文件是正常可用的图片文件呢?
If FileSys.FileExists(str) Then
                    Dim img As image = getImage(str)
                    Dim bmp As new bitmap(img, 30,40)
                    bmp.save(str1)
                    bmp.Dispose
                    If FileSys.FileExists(str1) Then
                        e.Graphics.DrawImage(getImage(str1),e.x +1,e.y+1,e.Width - 2,e.Height - 2)
                        e.Text = ""
                    Else
                        e.Text = "待下载"
                    End If
                End If

--  作者:有点蓝
--  发布时间:2022/11/11 15:32:00
--  
If FileSys.FileExists(str) Then
    Dim img As image = getImage(str)
    If img IsNot Nothing Then
        Dim bmp As New bitmap(img, 30, 40)
        bmp.save(str1)
        bmp.Dispose
        If FileSys.FileExists(str1) Then
            e.Graphics.DrawImage(getImage(str1), e.x + 1, e.y + 1, e.Width - 2, e.Height - 2)
            e.Text = ""
        Else
            e.Text = "待下载"
        End If
    End If
End If

--  作者:fendouww
--  发布时间:2022/11/11 15:52:00
--  
图片点击可在新窗口打开查看还是不行,那就是在保存的时候出错了
--  作者:有点蓝
--  发布时间:2022/11/11 15:55:00
--  
贴出完整代码
--  作者:fendouww
--  发布时间:2022/11/11 16:18:00
--  
If e.Col.Name = "图片" Then
    If xiantu = True Then
        If e.Row.IsNull(e.Col.Name) = False Then
            Dim cs As new List(of String)
            cs = e.Row.DataRow.Lines(e.Col.Name)
            Dim js As String() = cs.ToArray()
                    e.StartDraw
                    Dim str As String = "\\\\10.100.100.229\\foxtable资料\\图片\\" & js(0).trim("\\")
                    Dim str1 As String = str.Insert(str.LastIndexOf("."), "--")
                    If FileSys.FileExists(str1) Then
                        e.Graphics.DrawImage(getImage(str1),e.x +1,e.y+1,e.Width - 2,e.Height - 2)
                        e.Text = ""
                    ElseIf FileSys.FileExists(str) Then
                        Dim img As image = getImage(str)
                        Dim bmp As New bitmap(img, 30, 40)
                        bmp.save(str1)
                        bmp.Dispose
                        If FileSys.FileExists(str1) Then
                            e.Graphics.DrawImage(getImage(str1),e.x +1,e.y+1,e.Width - 2,e.Height - 2)
                            e.Text = ""
                        Else
                            e.Text = "待下载"
                        End If
                    End If
                    e.EndDraw
    Else
        e.Text = e.Row("汇总")
    End If
End If
附件是错误文件

--  作者:有点蓝
--  发布时间:2022/11/11 16:20:00
--  
代码有好几个getImage,全部都要判断