#include <stdio.h>
#include "jpeglib.h"
#include <setjmp.h>
extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */
extern int image_height; /* Number of rows in image */
extern int image_width; /* Number of columns in image */
void encode_jpeg_file (char * filename, int quality)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE * outfile; /* target file */
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
int row_stride; /* physical row width in image buffer */
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
if ((outfile = fopen(filename, "wb")) == NULL) {
fprintf(stderr, "can't open %s/n", filename);
exit(1);
}
jpeg_stdio_dest(&cinfo, o
encode RGB24 to jpeg, using libjpeg
最新推荐文章于 2023-10-20 16:12:22 发布
这段代码展示了如何使用libjpeg库将RGB24格式的图像数据编码并保存为JPEG文件。它定义了一个名为`encode_jpeg_file`的函数,接受图像文件名和质量参数,通过设置JPEG压缩结构、打开文件、设置图像属性、设置质量、开始压缩、写入扫描线并完成压缩来实现这一过程。

最低0.47元/天 解锁文章
309

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



