2010-10-17 53 views
2

當我使用bitmap.save保存jpg文件時,當我指定編碼器和質量時,它保存爲JPEG 4-1-1,但是當我不指定編碼器和質量時,保存爲4-2-2。我想把它保存爲4-2-2,質量比默認值高。這可能使用bitmap.save?用4-1-1保存我會失去什麼嗎?如何在.net中以4-2-2和高質量保存jpeg?

Dim bmp As Bitmap 
Dim ep As New EncoderParameters(1) 
Dim sysCodecs() As ImageCodecInfo 
Dim jpgCodec, cdc As ImageCodecInfo 

sysCodecs = ImageCodecInfo.GetImageEncoders() 

' get jpg codec 
jpgCodec = Nothing 
For Each cdc In sysCodecs 
    If String.Compare(cdc.MimeType, "image/jpeg", True) = 0 Then 
    jpgCodec = cdc 
    Exit For 
    End If 
Next cdc 

If jpgCodec IsNot Nothing Then 
    ep.Param(0) = New EncoderParameter(Encoder.Quality, 97) 
    bmp = Bitmap.FromFile(filename) 
    bmp.Save(outname, jpgCodec, ep) ' saves 4-1-1 
    bmp.Save(outname) ' saves 4-2-2 
end if 

回答