C # method for processing JPEG header information

Source: Internet
Author: User

Someone once gave me a jpg with a size of 1024*1024 and a size of 99 kb. The size of each layer is as follows: Unit: kb

The jpg pyramid I generated is processed by any

Height256 46.2kb

Height512 162kb

Height1024 557kb

The jpg pyramid generated by Photoshop is processed by any processing

Height256 48kb

Height512 90kb

Height1024 163kb

It can be seen that the size of this image is too big to be understood. I finally read the previous blog post and read the metadata to see why:

Retrieve metadata Functions

Copy codeThe Code is as follows: public void GetProperty ()

{

Bitmap myImage1024 = new Bitmap (@ "E: \ myjpg \ height.jpg ");

Foreach (PropertyItem property in myImage1024.PropertyItems)

{

StringBuilder sb = new StringBuilder ();

Byte [] sbbyte = (Byte []) property. Value;

Sb. AppendFormat ("ID: {0}, Length: {1}, Type: {2}; \ n ",

Property. Id. ToString (), property. Len. ToString (), property. Type. ToString (),);

Console. Write (sb );

}

}

I found that the generated jpg file is different from the metadata of the original image.

Height1024:

ID: 771, Length: 1, Type: 1; header information Tag explanation: 303 PropertyTagSRGBRenderingIntent

ID: 769, Length: 8, Type: 5; header information Tag explanation: 301 PropertyTagGamma

ID: 20752, Length: 1, Type: 1; header information Tag explanation: 5110 PropertyTagPixelUnit resolution

ID: 20753, Length: 4, Type: 4; header information Tag explanation: 5111 PropertyTagPixelPerUnitX

ID: 20754, Length: 4, Type: 4; header information Tag explanation: 5112 PropertyTagPixelPerUnitY

Height:

ID: 20625, Length: 128, Type: 3; header information Tag explanation: 5091 PropertyTagChrominanceTable

ID: 20624, Length: 128, Type: 3; header information Tag explanation: 5090 PropertyTagLuminanceTable

In this way, we can see why jpg is different in size. Well, I modified the method for generating the image pyramid: Remove their header information before saving the pyramid. Then I was surprised to find that the finest layer of the image pyramid I generated is the same size as the original image !.

Methods for removing image metadata:

Copy codeThe Code is as follows: public void RemoveProperty ()

{

Bitmap myImage1024 = new Bitmap (@ "E: \ myjpg \ height.jpg ");

Foreach (PropertyItem property in myImage1024.PropertyItems)

{

MyImage1024.RemovePropertyItem (property. Id );

}

MyImage1024.Save (@ "E: \ myjpg \ nopro.jpg ");

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.