简体   繁体   中英

How in C# can I tell if a JPEG image is progressive

A JPEG can be either encoded in different ways; Base Line, Progressive etc.

How can I determine if progressive was used in C#

Based on the HTML version http://techslides.com/demos/progressive-test.html a JPEG that is encoded progressively contains the bytes FFC2.

The FFC2 marker shows the start of frame that is only present in progressive images.

var imageUrl = "progress.jpg";

using (var wc = new WebClient())
{
   byte[] imageBytes = wc.DownloadData(imageUrl);

   string hex = BitConverter.ToString(imageBytes.Take(500).ToArray());
   var imageAsHex = hex.Replace("-", "").ToUpper();

   Console.WriteLine("Is JPEG: " + imageAsHex.Contains("FFD8"));
   Console.WriteLine("Is Progressive: " + imageAsHex.Contains("FFC2"));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM