Foxtable(狐表)用户栏目专家坐堂 → 改变图片文件类型


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

主题:改变图片文件类型

帅哥哟,离线,有人找我吗?
刘林
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1936 积分:14844 威望:0 精华:0 注册:2016/4/28 9:58:00
改变图片文件类型  发帖心情 Post By:2018/9/19 18:35:00 [只看该作者]

 If wjm>""
        Dim ifo As new FileInfo(t1)
        Dim img As image = getimage(t1)
        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, 100) ' 质量级别 0 对应于最大压缩,而质量级别 100 对应于最小压缩
        myEncoderParameters.Param(0) = myEncoderParameter
        Dim slt As String =  ifo.path & wjm & ifo.Extension
        bmp.Save(slt,jpgEncoder, myEncoderParameters)
        bmp.dispose
        g.dispose
        Dim img1 As image = getImage(slt)
        Dim bmp1 As bitmap
        If img1.width > 200 Then
            If 200 * (img1.height / img1.width) > 150 Then
                bmp1 = new bitmap(img1, 200*(150/(200*(img1.height/img1.width))), 150)
            Else
                bmp1 = new bitmap(img1, 150, 150 * (img1.height / img1.width))
            End If
            bmp1.save(slt)
            bmp1.Dispose
        End If
        If ftp1.Upload(slt,"\xp\" & FileSys.GetName(wjm & Ifo.extension),True) = True Then
            r("相片")="\xp\" & FileSys.GetName(wjm & Ifo.extension)
            r.save
        Else
            Messagebox.show("上传失败,请重新上传该文件!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        End If
    Else
        
    End If
Else
    

请问老师,当图片t1为非jpg文件类型时,我想在保存时统一保存为jpg类型,直接改扩展明应该不行吧,这个在哪里更改?

顺便加一个问题用命令如何让当前行的图片字段的图片刷新呢?
[此贴子已经被作者于2018/9/19 19:05:52编辑过]

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/9/19 20:43:00 [只看该作者]

1、压缩代码要改一下

 

http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=124985&replyID=840268&skin=1

 

2、保存的时候修改


bmp1.save(slt, ImageFormat.Jpeg)

 


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


加好友 发短信
等级:八尾狐 帖子:1936 积分:14844 威望:0 精华:0 注册:2016/4/28 9:58:00
  发帖心情 Post By:2018/9/19 21:04:00 [只看该作者]

Dim ftp1 As New FtpClient
ftp1.Host=
ftp1.Account = 
ftp1.Password =
Dim r As Row = Tables("相片处理_table1").Current
Dim t1 As String = e.Form.Controls("textbox1").text
Dim wjm As String=""
If t1>""
    If ValidPIN(r("身份证件号"))= True
        wjm = r("身份证件号")
    ElseIf r("学籍号")>""
        wjm=r("学籍号")
    Else
        messagebox.show("该学生的身份证号和学籍号中至少有一个要正确完整")
        Return
    End If
    If wjm>""
        Dim ifo As new FileInfo(t1)
        If  Ifo.Length>40960 '大于40k才压缩
            Dim img As image = getimage(t1)
            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, 100) ' 质量级别 0 对应于最大压缩,而质量级别 100 对应于最小压缩
            myEncoderParameters.Param(0) = myEncoderParameter
            Dim slt As String =  ifo.path & wjm & ifo.Extension
            bmp.Save(slt,jpgEncoder, myEncoderParameters)
            bmp.dispose
            g.dispose
            Dim img1 As image = getImage(slt)
            Dim bmp1 As bitmap
            If img1.width > 200 Then
                If 200 * (img1.height / img1.width) > 150 Then
                    bmp1 = new bitmap(img1, 200*(150/(200*(img1.height/img1.width))), 150)
                Else
                    bmp1 = new bitmap(img1, 150, 150 * (img1.height / img1.width))
                End If
                bmp1.save(slt, ImageFormat.Jpeg)
                bmp1.Dispose
            End If


            If ftp1.Upload(slt,"\xp\" & FileSys.GetName(wjm & Ifo.extension),True) = True Then
                r("相片")="\xp\" & FileSys.GetName(wjm & Ifo.extension)
                r.save
            Else
                Messagebox.show("上传失败,请重新上传该文件!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
            End If
            
        Else
            If ftp1.Upload(t1,"\xp\" & FileSys.GetName(wjm & Ifo.extension),True) = True Then
                r("相片")="\xp\" & FileSys.GetName(wjm & Ifo.extension)
                r.save
            Else
                Messagebox.show("上传失败,请重新上传该文件!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
            End If
            
        End If
    
    End If
Else
    messagebox.show("你没打开相片")
End If


我测试了一下选择个png文件传上去后文件还是png呢哪里没有对?


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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/9/19 21:46:00 [只看该作者]

Dim slt As String =  ifo.path & wjm & ifo.Extension

 

改成

 

Dim slt As String =  ifo.path & wjm & ".jpg"


 回到顶部