开发者

How do you save a jpeg with 4-2-2 and high quality in .net?

开发者 https://www.devze.com 2023-01-20 03:32 出处:网络
When I save a jpg file using bitmap.save, it saves as jpeg 4-1-1 when I specify the encoder and quality, but as 4-2-2 when I don\'t. I would like to save it as 4-2-2 with a higher quality than the def

When I save a jpg file using bitmap.save, it saves as jpeg 4-1-1 when I specify the encoder and quality, but as 4-2-2 when I don't. I would like to save it as 4-2-2 with a higher quality than the default. Is that possible using bitmap.save? Do I lose anything by saving with 4-1-1?

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开发者_如何学Python.FromFile(filename)
  bmp.Save(outname, jpgCodec, ep) ' saves 4-1-1
  bmp.Save(outname) ' saves 4-2-2
end if


It is not possible to change chroma subsampling in GDI+:

  • http://www.windows-tech.info/13/182be886cf7447bc.php
  • http://forums.asp.net/p/1538597/3763627.aspx
  • http://www.codeguru.com/forum/archive/index.php/t-494480.html

I had to use a third party tool (Leadtools RasterImage Library) to accomplish this.

0

精彩评论

暂无评论...
验证码 换一张
取 消