jepg图像的存储 转

先把代码贴上:

extern "C"

{

#include "jpeglib.h"

#pragma comment(lib,"libjpeg.lib")

//把无压缩的图像数据(纹理)存储成jepg

bool appSaveJpegRGB(char *filepath,unsigned char * data,int width,int height)

{

unsigned char *Data = data;

int nWidth = width;

int nHeight = height;

struct jpeg_compress_struct jcs;

struct jpeg_error_mgr jem;

jcs.err = jpeg_std_error(&jem);

jpeg_create_compress(&jcs);

FILE *f;

f=fopen(filepath,"wb");

if (f==NULL) 

{

return false;

}

jpeg_stdio_dest(&jcs, f);

jcs.image_width = nWidth;

jcs.image_height = nHeight;

jcs.input_components = 3;

jcs.in_color_space = JCS_RGB;

jpeg_set_defaults(&jcs); 

jpeg_set_quality (&jcs, 80, true);

jpeg_start_compress(&jcs, TRUE);

JSAMPROW row_pointer[1];

int row_stride;

row_stride = jcs.image_width*3;

while (jcs.next_scanline < jcs.image_height) {

row_pointer[0] = & Data[jcs.next_scanline * row_stride];

jpeg_write_scanlines(&jcs, row_pointer, 1);

}

jpeg_finish_compress(&jcs);

jpeg_destroy_compress(&jcs);

fclose(f);

return true;

}

};

//最近做项目老外要求把截屏数据存储成jepg格式的,说bmp的太占用空间,于是逼着我去找一jpeg存储的资料,这不找到了。

首先要我得到了差不多的存储代码,就上面那些网上到处都是。

然后需要一个libjpeg库,于是去IJP下了一个官方jpeg-8c版本的库,下完之后发现里面没有编译好的lib,然后还要自己编译一个,哎,他妈的太麻烦了,用vc都快把自己用成傻瓜了。

首先,看看怎样安装它,打开intstall.txt 里面有下面这一段英文,显然我们要把jconfig.vc放到jconfig.h中,没有这个文件就NEW一个,还有个makefile什么的,就是改成一个标准的windows平台的makefile的名字,这个没必要动。下面准备编译。

我的编译环境是VC2008,首先启动cmd 运行vc目录中的vcvars32.bat,貌似把当前窗口的路径设定成vc编译的环境路径(差不多),但是不要关闭窗口,关闭的话就不好使了,然后运行nmake -f makefile.vc ,过了一会libjpeg.lib诞生了。


-----------------------------------------------------------------------------

If you have one of these systems, you can just use the provided configuration

files:

 

Makefilejconfig fileSystem and/or compiler

 

makefile.manxjconfig.manxAmiga, Manx Aztec C

makefile.sasjconfig.sasAmiga, SAS C

makeproj.macjconfig.macApple Macintosh, Metrowerks CodeWarrior

mak*jpeg.stjconfig.stAtari ST/STE/TT, Pure C or Turbo C

makefile.bccjconfig.bccMS-DOS or OS/2, Borland C

makefile.djjconfig.djMS-DOS, DJGPP (Delorie's port of GNU C)

makefile.mc6jconfig.mc6MS-DOS, Microsoft C (16-bit only)

makefile.watjconfig.watMS-DOS, OS/2, or Windows NT, Watcom C

makefile.vcjconfig.vcWindows NT/95, MS Visual C++

make*.vc6jconfig.vcWindows NT/95, MS Visual C++ 6

make*.v10jconfig.vcWindows NT/95, MS Visual C++ 2010 (v10)

makefile.mmsjconfig.vmsDigital VMS, with MMS software

makefile.vmsjconfig.vmsDigital VMS, without MMS software

 

Copy the proper jconfig file to jconfig.h and the makefile to Makefile (or

whatever your system uses as the standard makefile name).  For more info see

the appropriate system-specific hints section near the end of this file.

posted on 2011-09-29 17:32  carekee  阅读(902)  评论(0编辑  收藏  举报