以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  请问,压缩图片  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=141401)

--  作者:wandongliang
--  发布时间:2019/9/28 11:00:00
--  请问,压缩图片
请问以下,以下这段代码,我想加个压缩图片进去,该怎么改?

        For Each key As String In e.PostValues.Keys
            If key.Contains("imgs_") Then
                Dim bs As Byte() = Convert.FromBase64String(e.PostValues(key).split(",")(1))
                Dim stream As System.IO.Stream = New System.IO.MemoryStream(bs)
                Dim bmp As System.Drawing.Bitmap = New System.Drawing.Bitmap(stream)
                bmp.Save(ProjectPath & "web/上传的文件/" & key & ".jpg", System.Drawing.Imaging.ImageFormat.Png)
                MessageBox.Show(ProjectPath & "web/上传的文件/" & key & ".jpg")
            End If
        Next

--  作者:有点蓝
--  发布时间:2019/9/28 11:13:00
--  
参考:

Dim bmpDest As New Bitmap(100, 100)
Dim bmpSrc As New Bitmap("F:\\Materials\\image\\1234.jpg")
Dim g = Graphics.FromImage(bmpDest)
Dim rectDest As New System.Drawing.Rectangle(0, 0, 100, 100)
Dim rectSrc As New System.Drawing.Rectangle(0, 0, bmpSrc.Width, bmpSrc.Height)
g.DrawImage(bmpSrc, rectDest, rectSrc, GraphicsUnit.Pixel)
g.Dispose()
bmpDest.Save("F:\\Materials\\image\\4321.jpg",img.RawFormat)

--  作者:wandongliang
--  发布时间:2019/9/28 13:30:00
--  
蓝老师,以下代码中,有一段出现报错,但是这是按照例子做出来了,麻烦帮帮看下是哪里不对

    If key.Contains("imgs_") Then
MessageBox.Show(1)
        Dim wjm As String = rand.NextString(10)
        Dim bs As Byte() = Convert.FromBase64String(e.PostValues(key).split(",")(1))
        Dim stream As System.IO.Stream = New System.IO.MemoryStream(bs)
MessageBox.Show(2)
        Dim bmp As System.Drawing.Bitmap = New System.Drawing.Bitmap(stream)
MessageBox.Show(21)
        bmp.Save(ProjectPath & "web/商品原图/" & key & ".jpg", System.Drawing.Imaging.ImageFormat.Png)     ‘这段代码报错,显示“调用的目标发生了异常。GDI+中发生一般性错误”
MessageBox.Show(22)
        FileSys.RenameFile(ProjectPath & "web/商品原图/" & key & ".jpg", wjm & ".jpg")
MessageBox.Show(3)
        Dim newname = wjm & ".jpg"
        Files = Files & IIF(Files > "" , vbcrlf, "") & newName
        FileSys.CopyFile(ProjectPath & "web\\商品原图\\" & newname,ProjectPath & "web\\商品大图\\" & newname,True)
MessageBox.Show(4)
        Dim file As String = ProjectPath & "web\\商品大图\\" & newName
        Dim img As image = getImage(file)
        Dim bmp1 = new bitmap(img, 300, 700)
MessageBox.Show(5)
        bmp1.save(ProjectPath & "web\\商品大图\\" & newname)
        bmp1.Dispose
        FileSys.CopyFile(ProjectPath & "web\\商品原图\\" & newname,ProjectPath & "web\\商品缩略图\\" & newname,True)
MessageBox.Show(6)
        file = ProjectPath & "web\\商品缩略图\\" & newName
        img = getImage(file)
        bmp1 = new bitmap(img, 300, 700)
MessageBox.Show(7)
        bmp1.save(ProjectPath & "web\\商品大图\\" & newname)
        bmp1.Dispose
    End If

--  作者:有点蓝
--  发布时间:2019/9/28 14:18:00
--  
bmp.Save(ProjectPath & "web/商品原图/" & key & ".jpg")
或者
bmp.Save(ProjectPath & "web/商品原图/" & key & ".png")