CImg、libjpeg--介紹、配置(操作JPEG)
阿新 • • 發佈:2017-08-16
variable program pau class keyword download 一個 壓縮 makefile
直接上代碼了:
關於處理圖片,之前寫了兩篇博客關於ImageMagick的:
《ImageMagick–介紹》
《ImageMagick–VS2015環境配置、開發(registrykeylookupFailed)》
可是。在沒有安裝ImageMagick的機器上。會報錯。我們須要改動源文件。改變code path。
這有點尷尬。成本有點高,所以今天就再介紹介紹CImg,來搞一搞。
僅僅須要一個head就能夠搞定了。
CImg介紹:
The CImg Library is a small, open-source, and modern C++ toolkit for image processing。
網址:
http://cimg.eu/download.shtml
下載後解壓:
圖1
接下來就是新建project了。然後包括頭文件就能夠了。
接下來介紹一下 怎樣操作JPEG文件。
libjpeg介紹
libjpeg庫是專門用於jpeg圖片格式解壓和壓縮的庫
網址:
http://libjpeg.sourceforge.net/
解壓,最基本的是編譯:
1改動makefile.vc
# Pull in standard variable definitions
!include <C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1 A\Include\Win32.Mak>
也就是改動到自己電腦上Win32.Mak所在的位置。假設出現錯誤:
makefile.vc(11) : fatal error U1052: 未找到文件“Win32.Mak”
就要再細致檢查檢查路徑了。
2把jconfig.vc改為jconfig.h
否則出現錯誤:
fatal error U1073: 不知道怎樣生成“jconfig.h”
3使用visual studio的命令行工具
d:\libjpeg\jpeg_vs2013\jpeg-6b>nmake /f makefile.vc
這時候就會出現libjpeg.lib
使用CImg和libjpeg
直接上代碼了:
#include<iostream>
#define XMD_H
#define cimg_use_jpeg
#include "CImg.h"
int main()
{
std::string path = "00.JPG";
std::string save_path = "02.JPG";
cimg_library::CImg<unsigned char>image(path.c_str());
image.get_resize(1600, 900, -100, -100, 1).save_jpeg(path.c_str(), 100);
system("pause");
return 0;
}
CImg、libjpeg--介紹、配置(操作JPEG)