以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  怎样设置图片的分辩率,达到控制图片文件大小的效果?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=67185)

--  作者:zgjmost
--  发布时间:2015/4/20 8:30:00
--  怎样设置图片的分辩率,达到控制图片文件大小的效果?

怎样设置图片的分辩率,达到控制图片文件大小的效果?

 

 


图片点击可在新窗口打开查看此主题相关图片如下:20154201392622425.jpg
图片点击可在新窗口打开查看

--  作者:Bin
--  发布时间:2015/4/20 8:34:00
--  
http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=24571&skin=0
--  作者:zgjmost
--  发布时间:2015/4/20 8:55:00
--  
 

Public Sub AdjustImageSize(ByVal paraImg As Image, ByVal ParaIntWidth As Integer, ByVal ParaIntHeight As Integer, ByVal ParaStrSaveLoc As String)

\'参数说明:paraImg 原始图象; ParaIntWidth 调整的宽度; ParaIntHeight 调整的高度; ParaStrSaveLoc 保存路径

Dim Bmp As New Bitmap(ParaIntWidth, ParaIntHeight)

Dim Gr As Graphics

Gr = Graphics.FromImage(Bmp)

\'设置 System.Drawing.Graphics对象的SmoothingMode属性为HighQuality

Gr.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed

\'下面这个也设成高质量

Gr.CompositingQuality = Drawing2D.CompositingQuality.HighSpeed

\'下面这个设成High

Gr.InterpolationMode = Drawing2D.InterpolationMode.Low

\'把原始图像绘制成上面所设置宽高的缩小图

Dim rectDestination As Rectangle = New System.Drawing.Rectangle(0, 0, ParaIntWidth, ParaIntHeight)

Gr.DrawImage(paraImg, rectDestination, 0, 0, paraImg.Width, paraImg.Height, GraphicsUnit.Pixel)

Dim Ep As Imaging.EncoderParameters = New Imaging.EncoderParameters(1)

Ep.Param(0) = New System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100)

Dim myImageCodecInfo As ImageCodecInfo

myImageCodecInfo = GetEncoderInfo("image/jpeg")

If myImageCodecInfo Is Nothing Then

    Bmp.Save(ParaStrSaveLoc, Imaging.ImageFormat.Jpeg)

Else

    Bmp.Save(ParaStrSaveLoc, myImageCodecInfo, Ep)

End If

Bmp.Dispose()

End Sub

 

Public Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo

Dim j As Integer

Dim encoders() As ImageCodecInfo

encoders = ImageCodecInfo.GetImageEncoders()

For j = 0 To encoders.Length - 1 \'(j = 0; j < encoders.Length; ++j)

    If encoders(j).MimeType = mimeType Then

        Return encoders(j)

    Else

        Return Nothing

    End If

Next

End Function


--  作者:zgjmost
--  发布时间:2015/4/20 8:56:00
--  

上面哪一个是设置分辩率的参数?


--  作者:Bin
--  发布时间:2015/4/20 9:02:00
--  
Gr.DrawImage(paraImg, rectDestination, 0, 0, paraImg.Width, paraImg.Height, GraphicsUnit.Pixel)