Save JPG in progressive format

前端 未结 2 1898
北恋
北恋 2021-01-02 16:39
 _
Public Sub Save(ByVal b As Bitmap, ByVal FileName As String, ByVal Compression As Long, ByVal MimeType As String)
    Dim Params As EncoderPara         


        
相关标签:
2条回答
  • 2021-01-02 17:15

    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.

    0 讨论(0)
  • 2021-01-02 17:18

    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
    
    0 讨论(0)
提交回复
热议问题