以渐进格式保存 JPG

发布于 2024-08-21 13:47:02 字数 556 浏览 5 评论 0原文

<Extension()> _
Public Sub Save(ByVal b As Bitmap, ByVal FileName As String, ByVal Compression As Long, ByVal MimeType As String)
    Dim Params As EncoderParameters = New EncoderParameters(2)
    Dim CodecInfo As ImageCodecInfo = GetEncoderInfo(MimeType)

    Params.Param(0) = New EncoderParameter(Encoder.RenderMethod, EncoderValue.RenderProgressive)
    Params.Param(1) = New EncoderParameter(Encoder.Quality, Compression)

    b.Save(FileName, CodecInfo, Params)
End Sub

这是行不通的。它不保存为渐进式。我该如何做到这一点,也许还可以指定通行证的编号。?

<Extension()> _
Public Sub Save(ByVal b As Bitmap, ByVal FileName As String, ByVal Compression As Long, ByVal MimeType As String)
    Dim Params As EncoderParameters = New EncoderParameters(2)
    Dim CodecInfo As ImageCodecInfo = GetEncoderInfo(MimeType)

    Params.Param(0) = New EncoderParameter(Encoder.RenderMethod, EncoderValue.RenderProgressive)
    Params.Param(1) = New EncoderParameter(Encoder.Quality, Compression)

    b.Save(FileName, CodecInfo, Params)
End Sub

this does not work. Its not saved as progressive. How can i do this, and maybe also specify the nr of passes.??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玉环 2024-08-28 13:47:02

据我所知,它不受支持。我已尝试此处此处 并得出此 C# 代码:

using (Image source = Image.FromFile(@"D:\temp\test2.jpg")) {

  ImageCodecInfo codec = ImageCodecInfo.GetImageEncoders().First(c => c.MimeType == "image/jpeg");

  EncoderParameters parameters = new EncoderParameters(3);
  parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
  parameters.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.ScanMethod, (int)EncoderValue.ScanMethodInterlaced);
  parameters.Param[2] = new EncoderParameter(System.Drawing.Imaging.Encoder.RenderMethod, (int)EncoderValue.RenderProgressive);

  source.Save(@"D:\temp\saved.jpg", codec, parameters);
}

设置隔行和逐行模式,仍然保存常规基线 JPEG。我尝试过任一设置及其替代设置(非隔行扫描和非逐行扫描)的任意组合,并且在生成的图像文件中没有看到任何差异。

我还没有找到任何人的回应说他们实际上已经设法在 .NET 中保存渐进式 JPEG。

ScanMethodInterlacedRenderProgressive 参数值均仅描述为“在 GDI+ 版本 1.0 中未使用”。在
文档

As far as I can tell, it's not supported. I have tried code suggested here and here and arrived at this C# code:

using (Image source = Image.FromFile(@"D:\temp\test2.jpg")) {

  ImageCodecInfo codec = ImageCodecInfo.GetImageEncoders().First(c => c.MimeType == "image/jpeg");

  EncoderParameters parameters = new EncoderParameters(3);
  parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
  parameters.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.ScanMethod, (int)EncoderValue.ScanMethodInterlaced);
  parameters.Param[2] = new EncoderParameter(System.Drawing.Imaging.Encoder.RenderMethod, (int)EncoderValue.RenderProgressive);

  source.Save(@"D:\temp\saved.jpg", codec, parameters);
}

Setting both interlaced and progressive mode, it still saves a regular baseline JPEG. I have tried any combination of either setting and their alternative settings (non-interlaced and non-progressive), and haven't seen any difference at all in the resulting image file.

I haven't found any response from anyone saying that they have actually managed to save a progressive JPEG in .NET.

Both the ScanMethodInterlaced and RenderProgressive parameter values are described only as "Not used in GDI+ version 1.0." in
the documentation
.

泪眸﹌ 2024-08-28 13:47:02

我想使用 jpegtran 实用程序,如 图像优化,第 4 部分:渐进式 JPEG…热与否? 文章:

jpegtran -copy none -progressive input.jpg output.jpg

此外,您还可以通过以下方式优化 Haffman 表:

jpegtran -copy none -optimize input.jpg output.jpg

I suppose to use jpegtran utility as described in Image Optimization, Part 4: Progressive JPEG…Hot or Not? article:

jpegtran -copy none -progressive input.jpg output.jpg

In addition you can optimize Haffman tables by such way:

jpegtran -copy none -optimize input.jpg output.jpg
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文