使用vb.net进行图像压缩 [英] image compression using vb.net

查看:341
本文介绍了使用vb.net进行图像压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个用于图像压缩的vb.net源代码

i need a vb.net source code for image compression

推荐答案

然后谷歌为它。我们不会为你研究你的代码。顺便说一下,你有很好的理由没有在网上看到很多用于图像处理的VB.NET代码。
Then Google for it. Were not going to do your research not quite your code for you. By the way, there''s a good reason why you don''t see a lot of VB.NET code for image manipulation on the web.


将图像保存为.jpg和指定压缩率:



Save an image as a .jpg and specify compression ratio:

Private Class JpegTools
     Private codecs As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
     Private quality As Long

     Public ici As ImageCodecInfo = Nothing
     Public ep As New EncoderParameters()
     Public compressionRatio As Long

     Public Sub new(ByVal _compressionRatio As Long, Optional ByRef errMsg As String = "")

         compressionRatio    = _compressionRatio
         If compressionRatio < 0 then compressionRatio = 0
         If compressionRatio > 100 then compressionRatio = 100
         quality             = (100 - compressionRatio)

         Try
             For Each codec As ImageCodecInfo In codecs
                 If codec.MimeType = "image/jpeg" Then
                     ici = codec
                 End If
             Next

             ep.Param(0) = New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality)
         Catch ex As Exception
             errMsg = ex.Message
         End Try
     End Sub
 End Class

 Private JpgTools As JpegTools

 ' Save an Image() to a jpeg file and specify the compression % (Valid values for compressionRatio are 0 - 100)
 Public Function SaveImgToFile(ByRef img As Image, ByVal fullPathWithFileName As String, ByVal compressionRatio As Long, _
                               Optional ByRef errMsg As String = "") As Boolean

     If JpgTools Is Nothing Then JpgTools = New JpegTools(compressionRatio, errMsg)
     If JpgTools.compressionRatio <> compressionRatio then JpgTools = New JpegTools(compressionRatio, errMsg)
     If errMsg <> "" then Return False

     Try
         img.Save(fullPathWithFileName, JpgTools.ici, JpgTools.ep)
     Catch ex As Exception
         errMsg = ex.Message
         Return False
     End Try

     Return True
 End Function


这篇关于使用vb.net进行图像压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆