下载到libjpeg源码后,解压,可以看到很多文档,想在VS2010中编辑使用,主要参考文件:install.txt 下面是我参考了说明文档以及网上一些资料后的编译过程: 编译过程: 1,下载libjpeg的源代码 下载地址:http://www.ijg.org/ 我下载到的是jpegsr8d.zip (有些人编译到此还会继续出现错误,见本文下方引用的其他解决办法。) 其中有一段在vs2010下的说明 We include makefiles that should work as project files in Visual Studio2010 or later. There is a library makefile that builds the IJG library To use: NMAKE /f makefile.vc setup-v10 This will move jconfig.vc to jconfig.h and makefiles to project files. (Note that the renaming is critical!) NMAKE /f makefile.vc test-build 5. Move the application .exe files from `app`\Release to an appropriate location on your path. Note: =====================================
测试程序: 1,在测试程序中工程属性-Linker-Input-Additional Dependencies中添加编译得到的jpeg.lib,同时将jpeg.lib文件放在测试代码同级目录下; 2,将libjpeg包中的头文件放在测试程序目录下,并在测试程序中添加对jpeglib.h和jmorecfg.h的引用(#include)。 即可在测试程序用用libjpeg库生成jpeg图像。 测试代码例子:本例转自http://blog.csdn.net/ani/article/details/2955189 ,我自己添加了几个参数设置,写图像数据时改了些数据 int _tmain(int argc, _TCHAR* argv[]) { //定义一个压缩对象,这个对象用于处理主要的功能 jpeg_compress_struct jpeg; //用于错误信息 jpeg_error_mgr jerr; //错误输出在绑定 jpeg.err = jpeg_std_error(&jerr);
//初始化压缩对象 jpeg_create_compress(&jpeg); //定义压缩后的输出,这里输出到一个文件! FILE* pFile = fopen( "c:\\tt.jpeg","wb" ); if( !pFile ) return 0; //绑定输出 jpeg_stdio_dest(&jpeg, pFile); //压缩参数设置。具体请到网上找相应的文档吧,参数很多,这里只设置主要的。 //我设置为一个 24 位的 512X512大小的RGB图片 jpeg.image_width = 512; jpeg.image_height = 512; jpeg.input_components = 3; jpeg.in_color_space = JCS_RGB; //参数设置为默认的 jpeg_set_defaults(&jpeg); //还可以设置些其他参数: //// 指定亮度及色度质量 //jpeg.q_scale_factor[0] = jpeg_quality_scaling(100); //jpeg.q_scale_factor[1] = jpeg_quality_scaling(100); //// 图像采样率,默认为2 * 2 //jpeg.comp_info[0].v_samp_factor = 1; //jpeg.comp_info[0].h_samp_factor = 1; //// 设定编码jpeg压缩质量 //jpeg_set_quality (&jpeg, 100, true); //开始压缩。执行这一行数据后,无法再设置参数了! jpeg_start_compress(&jpeg, TRUE); //定义一个数组,代表图片每一行的数据。3 代表 jpeg.input_components unsigned char oneRowImgData[ 512 * 3 ]; for( int i=0;i<512*3;++i ) oneRowImgData[i] = 0;
JSAMPROW row_pointer[1]; row_pointer[0] = oneRowImgData; //从上到下,设置图片中每一行的像素值 for( int i=0;i<jpeg.image_height;++i ) { int data = 0; for (int j = 0;j<jpeg.image_width*3;j=j+3) { oneRowImgData[j] = data%255;//R //oneRowImgData[j+1] = data%255;//G //oneRowImgData[j+2] = data%255;//B data ++; }
//将一行数据写入! jpeg_write_scanlines( &jpeg,row_pointer,1 ); } //结束压缩 jpeg_finish_compress(&jpeg); //清空对象 jpeg_destroy_compress(&jpeg);
fclose( pFile ); pFile = NULL; return 0; }
执行完毕后,会在C盘根目录下生成一个名为tt.jpeg的图片。 1、从ftp://ftp.simtel.net/pub/simtelnet/msdos/graphics/jpegsr6.zip下载libjpeg的源代码 2、解压出来一堆文件,打开命令行窗口(CMD),进入代码所放的目录下 3、运行命令:nmake /f makefile.vc nodebug=1 开始编译,然后问题就来了 4、“nmake 不是内部或外部命令” 5、makefile.vc<11>:fatal error U1052: file 'win32.mak' not found 6、NMAKE:fatal error U1073: don't know how to make 'jconfig.h' 7、NMAKE: fatal error U1077: '.../cl.EXE' : return code '0xc0000135' |
在VS2010下编译libjpeg及其应用例子
猜你喜欢
转载自blog.csdn.net/l_andy/article/details/79120173
今日推荐
周排行