如何在 .net 中以 4-2-2 格式保存高质量的 jpeg?
当我使用 bitmap.save 保存 jpg 文件时,当我指定编码器和质量时,它会保存为 jpeg 4-1-1,但当我不指定编码器和质量时,它会保存为 4-2-2。我想将其保存为 4-2-2,其质量比默认值更高。使用 bitmap.save 可以吗?通过 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.FromFile(filename)
bmp.Save(outname, jpgCodec, ep) ' saves 4-1-1
bmp.Save(outname) ' saves 4-2-2
end if
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.FromFile(filename)
bmp.Save(outname, jpgCodec, ep) ' saves 4-1-1
bmp.Save(outname) ' saves 4-2-2
end if
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无法更改 GDI+ 中的色度子采样:
我必须使用第三方工具(Leadtools RasterImage Library)来完成此任务。
It is not possible to change chroma subsampling in GDI+:
I had to use a third party tool (Leadtools RasterImage Library) to accomplish this.