Convert rgb bmp to JPEG

Source: Internet
Author: User

The method for converting RGB to JPEG: first pre-processing the image, then DCT transformation, quantization, and then encoding, Huffman encoding or other encoding to convert it to JPG. The following describes how to use opencv to save JPG images or use the ijg library to save JPG images. The functions of using opencv to save JPG images are as follows:

Cvapi (INT) cvsaveimage (const char * filename, const cvarr * image,
Const int * Params cv_default (0 ));
The third parameter sets the compression quality.

Int Params [3]

Params [0] = cv_imwrite_pai_quality;

Params [1] = 85; // sets the S compression degree.

Params [2] = 0;

Pass in Params.

 

The following describes how to use ijg to compress data:

First download ijg library, download the site is http://www.ijg.org, and then download the source code for compilation, compilation can refer to its documentation, I downloaded for jpegsr8c, according to its documentation, only the version libraries of vc6.0 and vs2010 can be compiled. I have not installed vs2010 software, so the libraries compiled by vc6.0 cannot be used, the reason may be that vc6.0 compiles a single thread, but I use multithreading. So I use vs2008 to re-compile the source code: the compilation method is as follows:

1. Create your own libjpeg Project
To facilitate the compilation after modification, and to make it easy to use the JPEG library in the VC environment, follow these steps to convert libjpeg to a project in the VC environment.
1. Create an empty static library project in the VC environment. The project name is jpeg. Note that the new project should not contain MFC or pre-compile the header file;
2. Set jcapimin. c jcapistd. c jccoefct. c jccolor. c jcdctmgr. c jchuff. c Under libjpeg.
Jcinit. c jcmainct. c jcmarker. c jcmaster. c jcomapi. c jcparam. c
Jcphuff. c jcprepct. c jcsample. c jctrans. c jdapimin. c jdapistd. c
Jdatadst. c jdatasrc. c jdcoefct. c jdcolor. c jddctmgr. c jdhuff. c
Jdinput. c jdmainct. c jdmarker. c jdmaster. c jdmerge. c jdphuff. c
Jdpostct. c jdsample. c jdtrans. c jerror. c jfdctflt. c jfdctfst. c
Jfdctint. c jidctflt. c jidctfst. c jidctint. c jidctred. c jquant1.c
Jquant2.c jutils. c jmemmgr. c
Jchuff. h jconfig. h jdhuff. h jdct. h jerror. h jinclude. h jmemsys. h jmorecfg. h
Jpegint. H. jpeglib. h jversion. h and other files are copied to the folder of the new project, and the. c file is renamed as. cpp;
3. Add all source files and header files to the new project;
4. Compile the new project and generate jpeg. Lib.

 

You can use it after compiling the library.

 

If anyone needs my compiled library, for vs2008, leave a message.

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.