标签:
1、libjpeg下载、编译
下载地址:http://libjpeg.sourceforge.net/
编译说明:http://m.blog.csdn.net/blog/oHanTanYanYing/42718959
static bool ipl2jpeg(IplImage *img, unsigned char **outbuffer, unsigned long*outlen) { unsigned char *outdata = (uchar *)img->imageData; struct jpeg_compress_struct cinfo = { 0 }; struct jpeg_error_mgr jerr; JSAMPROW row_ptr[1]; int row_stride; *outbuffer = NULL; *outlen = 0; cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); cinfo.image_width = img->width; cinfo.image_height = img->height; cinfo.input_components = img->nChannels; cinfo.in_color_space = JCS_RGB; jpeg_mem_dest(&cinfo, outbuffer, outlen); jpeg_set_defaults(&cinfo); jpeg_start_compress(&cinfo, TRUE); row_stride = img->width * img->nChannels; while (cinfo.next_scanline < cinfo.image_height) { row_ptr[0] = &outdata[cinfo.next_scanline * row_stride]; jpeg_write_scanlines(&cinfo, row_ptr, 1); } jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); return true; }
static bool jpegSave(const char* filename, unsigned char *outbuffer, unsigned long outlen) { FILE *f; fopen_s(&f, filename, "wb"); if (!f) return false; size_t size = fwrite(outbuffer, (size_t)outlen, 1, f); fclose(f); if (size == 1) return true; return false; }
标签:
原文地址:http://www.cnblogs.com/shon/p/4544370.html