Dim ftp1 As New FtpClient
ftp1.Host="
ftp1.Account =
ftp1.Password =
Dim r As Row = Tables("学生信息").Current
If ValidPIN(r("身份证件号"))= True
Dim dlg As New OpenFileDialog
dlg.Filter= "图像文件|*.bmp;*.jpg;*.png;*.gif"
If dlg.ShowDialog = DialogResult.OK Then
Dim ifo As new FileInfo(dlg.filename)
Dim img As image = getimage(dlg.filename)
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, 10) ' 质量级别 0 对应于最大压缩,而质量级别 100 对应于最小压缩
myEncoderParameters.Param(0) = myEncoderParameter
Dim slt As String = ifo.path & r("身份证件号") & ifo.Extension
bmp.Save(slt,jpgEncoder, myEncoderParameters)
bmp.dispose
g.dispose
If ftp1.Upload(slt,"\xp\" & FileSys.GetName(r("身份证件号") & Ifo.extension),True) = True Then
Messagebox.show("文件上传完成,请正确填写资料信息!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
r("相片")="\xp\" & FileSys.GetName(r("身份证件号") & Ifo.extension)
r.save
Else
Messagebox.show("上传失败,请重新上传该文件!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If
End If
Else
MessageBox.show("请注意,该学生的身份证件号不正确或不存在,请确定身份证件号后重新上传相片")
End If
老师,上面的的代码实现了选择图片并上传FTP,现在的问题是按这种将5M的图片压缩后大约有300+k,图片就不是好清晰了,我的想法是能不能压成几十K,图片的尺寸按比例缩小点,这样是不是清晰度就高点,并能小点,请问该怎样改?
[此贴子已经被作者于2017/12/11 16:13:57编辑过]