面对图像较大而带宽不足的情况,往往需要对图像进行压缩,使其变小后得以方便传输。
本文使用libjpeg(非libjpeg-turbo)实现了对图像的压缩。
1.encode_by_libjpeg.h
#include <iostream>
#include <fstream>
#include <cstring>
#include <jpeglib.h>
#include <setjmp.h>
int yuv420sp_to_jpeg(const char * filename, unsigned char* pdata,int image_width,int image_height, int quality);
int read_Image_from_raw_by_iostream(const std::string filename, unsigned char **buffer);
2.encode_by_libjpeg.cpp
#include "encode_by_libjpeg.h"
int yuv420sp_to_jpeg(const char * filename, unsigned char* pdata,int image_width,int image_height, int quality)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo); /*初始化*/
FILE * outfile; // target file
if ((outfile = fopen(filename, "wb")) == NULL) {
fprintf(

,利用libjpeg压缩为jpg图像,并统计耗时.&spm=1001.2101.3001.5002&articleId=140324033&d=1&t=3&u=784a8c56bfd043a388f71b5c75b79aa6)
401

被折叠的 条评论
为什么被折叠?



