libjpeg安装和使用
转自: http://blog.csdn.net/ice__snow/article/details/52563944 ,有几处做了一部分修改
一、 编译
下载地址 http://www.ijg.org/
1、下载并解压,放在一个好找的目录就行:
2、进入jpeg-9b,找到jconfig.vc,复制并改名为jconfig.h,否则会产生无法生成jconfig的警告
3、找到makefile.vc这个文件,打开(随便一个文本编辑器)找到这一行
把路径改为win32.mk在你电脑上的路径,每个人的可能不太一样,路径差别可能不是很大,我的是C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\win32.mak,改为
4、准备编译,我用的是VS2015命令提示符,不要选ARM的,选择 vs2015 x86 x64兼容工具命令提示符
5、进入jpeg-9b的目录,输入编译命令开始编译
命令:nmake -f makefile.vc
6、编译后在目录下找到库libjpeg.lib就编译成功了。
二、使用
具体的使用在目录下的example.c中有,注释非常细,看了基本就会用了。这里我简单说说用法。
1、使用配置
有两种方法:
第一种:添加libjpeg的头文件的路径和lib的路径到VS的工程中,项目属性页 ,然后在
中添加libjpeg.lib
第二种:把用到的头文件和libjpeg.lib拷到你的工程中,只在工程里做第一种的第三步添加libjpeg.lib就行了。
2、使用
程序里包含头文件#include <jpeglib.h>就行了。
大部分照搬,细节可以看里面的英语注释,主要的几个地方修改下就行了,看下面的汉语注释:
// 这些和错误处理有关,不用管
struct my_error_mgr {
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
};
typedef struct my_error_mgr * my_error_ptr;
METHODDEF(void) my_error_exit(j_common_ptr cinfo)
{
my_error_ptr myerr = (my_error_ptr)cinfo->err;
(*cinfo->err->output_message) (cinfo);
longjmp(myerr->setjmp_buffer, 1);
}
// 读取图像的函数
// 我添加了一个参数,是我库里的zMatrix类对象,用于保存读取的图片数据
GLOBAL(int) read_JPEG_file(char * filename, z::Matrix8u & img)
{
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
FILE * infile;
JSAMPARRAY buffer;
int row_stride;
if ((infile = fopen(filename, "rb")) == NULL) {
fprintf(stderr, "can't open %s\n", filename);
return 0;
}
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
if (setjmp(jerr.setjmp_buffer)) {
jpeg_destroy_decompress(&cinfo);
fclose(infile);
return 0;
}
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, infile);
// 这个函数获取了读取图片的信息,包括图片的高和宽
(void)jpeg_read_header(&cinfo, TRUE);
// 在这里添加你自己的代码,获取或用户到图像信息
img.create(cinfo.image_height, cinfo.image_width, 3);
(void)jpeg_start_decompress(&cinfo);
row_stride = cinfo.output_width * cinfo.output_components;
buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, 1);
while (cinfo.output_scanline < cinfo.output_height) {
// 一行一行的读取
(void)jpeg_read_scanlines(&cinfo, buffer, 1);
// 在这里添加代码获取到图片的像素数据
// buffer保存了读取的当前行的数据,保存顺序是RGB
// output_scanline是已经读取过的行数
for (int i = 0; i < img.cols; ++i) {
img[cinfo.output_scanline - 1][i * 3 + 2] = buffer[0][i * 3 + 0];
img[cinfo.output_scanline - 1][i * 3 + 1] = buffer[0][i * 3 + 1];
img[cinfo.output_scanline - 1][i * 3 + 0] = buffer[0][i * 3 + 2];
}
}
(void)jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
fclose(infile);
return 1;
}
代码:https://github.com/ffiirree/zMatrix/blob/master/zMatrix/zgui/zgui.cpp
LINUX 下的安装
1、下载在libjpeg到/usr/local/bin下
2、./configure --enable-shared --prefix=$CONFIGURE_PREFIX
3、make
4、make install
欢迎大家来我的新家看一看 3wwang个人博客-记录走过的技术之路
libjpeg安装和使用的更多相关文章
- phpize 扩展GD库 安装 ! 环境--centos 7 +nginx 1.7.11+php 5.6.7
使用phpize编译GD库安装,先安装前置库libjpeg libpng zlib freetype等 都是下面php编译的几个选项 先看php编译的选项: --with-gd=DIR ...
- 不重新编译PHP文件的情况下php GD库扩展库的编译安装(centos)
gd-2.0.33.tar.gz http://www.boutell.com/gd/ jpegsrc.v6b.tar.gz http://www.ijg.org/ libpng-1.2.7.tar. ...
- linux+GraphicsMagick 安装
转摘自:http://blog.csdn.net/fhqsse220/article/details/12995763 GraphicsMagick 安装 下载软件:download:ftp://ft ...
- nginx+php-fpm+mysql分离部署详解
相信大家将这三者部署到同一台主机应该已经不陌生了,今天在这里,给大家演示一下如何将三者部署到三台主机上. 实验系统:CentOS 6.6_x86_64 实验前提:大部分软件使用编译安装,请提前准备好编 ...
- 【转】Nginx+php-fpm+MySQL分离部署详解
转:http://www.linuxidc.com/Linux/2015-07/120580.htm Nginx+php-fpm+MySQL分离部署详解 [日期:2015-07-26] 来源:Linu ...
- 源码编译配置lnmp部署zabbix
环境说明: [root@wcy ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@wcy ~]# uname -a Linux ...
- Nginx php-fpm 分离搭建 (上) 未完
最近又重新看了一遍 'nginx入门到精通' 抽点时间 出来搭几个Demo 会有更深体会: Nginx如何与Php-fpm结合 Nginx不只有处理http请求的功能,还能做反向代理. ...
- debia下安装libjpeg
今天在编译时遇到如下问题: configure: error: no usable libjpeg; please install libjpeg devel package or equivalen ...
- Linux下安装过程中编译PHP时报错:configure: error: libjpeg.(a|so) not found
在Linux下安装PHP过程中,编译时出现configure: error: libjpeg.(a|so) not found 错误的解决的方法: 检查之后发现已经安装libjpeg.可是/usr/l ...
随机推荐
- hdu1799-循环多少次?-(组合恒等式)
循环多少次? Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- pom配置详解
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- aspectj ----- 简介
一.为什么写这个系列的博客 Aspectj一个易用的.功能强大的aop编程语言.其官网地址是:http://www.eclipse.org/aspectj/,目前最新版本为:1.7.0 RC1.但 ...
- Real Time Render 4
[Real Time Render 4] 1.Radiometry(辐射测试) deals with the measurement of electromagnetic(电磁) radiation( ...
- Displacement Mapping
[Displacement Mapping] Displacement Mapping(移位贴图). Normal maps的另一个应用是displacement mapping,在这个应用中,细节的 ...
- jmeter 在linux服务器的安装和运行;
linux环境下使用jmeter进行压力测试 标签(空格分隔): linux环境,jmeter linux环境下使用就meter进行压力测试: linux环境部署: 在Linux服务器先安装jdk: ...
- mysql中创建event定时任务
从网上借鉴大神的. use onlinexam; -- 查看event事件是否开启 show variables like '%sche%'; -- 开启event事件 (非常重要) set glo ...
- 安装sql server 2008 提示错误 SQL Server 2005 Express 工具。 失败
安装sql server 2008 management,提示错误:Sql2005SsmsExpressFacet 检查是否安装了 SQL Server 2005 Express 工具. 失败,已安装 ...
- 畅谈Redis和Memcached的区别
简述 memcached 和 redis 都很类似:都是内存型数据库,数据保存在内存中,通过tcp直接存取,优势是速度快,并发高,缺点是数据类型有限,查询功能不强,一般用作缓存. 那么题主说 memc ...
- TableView下拉刷新崩溃解决办法
return cell;上边加判断 if(self.dataArray.count<1){ return cell; }