C # Improving the Quality of jpg Images

Source: Internet
Author: User

Jpg images directly generated in the program, with Chinese characters with edges. After some searches, I found the following article on msdn that controls the jpg quality coefficient. I tried it after modification, the effect is indeed much better than the previous one. I don't know much about the principle. I posted the code and shared it with you.
The compression in the joint image Expert Group (JPEG) file is controlled by a group of quantization tables. Generally, there are two tables in each file: one for brightness information and the other for chrominance information. These tables are the 8x8 matrix with the Discrete Cosine values of 8x8 quantized.

JPEG quality coefficient is used to generate a pair of quantization tables. Many applications generate the same quantization table based on the independent JPEG group (IJG) Code and reference the code for IJG. However, some applications may use the custom quantization table.
The encoder parameter settings provided in the JPEG encoder System. Drawing Save the JPEG file. This encoder parameter complies with the range 1 to 100 using an integer convention. The value of this encoder parameter affects the creation and use of the quantization table and the recommended quality coefficient.

The Code is as follows:

System. Drawing. Image newimage = System. Drawing. Image. FromFile ("c: \ 00.jpg ");
Bitmap bt = new Bitmap (newimage );
Graphics g = Graphics. FromImage (bt );

(Code for drawing on the canvas is omitted in the middle)

String lujing = @ "c: 1.jpg ";

// Processing JPG Quality Functions
Int level = 100; // The range of image quality from 1
ImageCodecInfo [] codecs = ImageCodecInfo. GetImageEncoders ();
ImageCodecInfo ici = null;
Foreach (ImageCodecInfo codec in codecs)
{
If (codec. MimeType = "image/jpeg ")
Ici = codec;
}
EncoderParameters ep = new EncoderParameters ();
Ep. Param [0] = new EncoderParameter (System. Drawing. Imaging. Encoder. Quality, (long) level );

Bt. Save (lujing, ici, ep );
 
// Release the bitmap cache
Bt. Dispose ();

Related Article

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.