本文先把代码贴上,后续会讲解原理及实现过程
1、从官网上下载jpeg源码,编译成库(本人在windows下编译),编译方法网上很多,这里不叙述。
2、添加库文件和jpeglib.h、jmorecfg.h、jconfig.h至工程中
3、代码实现(VS2013)
#define JPEG_QUALITY 97 //它的大小决定jpg的质量好坏
//#include <atlbase.h>
#include <afxwin.h>
#include <iostream>
#include<ctime>
using namespace std;
extern "C" {
#include "jpeglib.h"
#include "jmorecfg.h"
#include "jconfig.h"
#include "jerror.h"
}
typedef struct /**** BMP file header structure ****/
{
unsigned int bfSize; /* Size of file */
unsigned short bfReserved1; /* Reserved */
unsigned short bfReserved2; /* ... */
unsigned int bfOffBits; /* Offset to bitmap data */
} BITMAPFILEHEADER1;
typedef struct /**** BMP file info structure ****/
{
unsigned int biSize; /* Si