0

所以我正在尝试 C++,我将从一些东西开始,我想,简单地压缩图像应该相当简单。

我的代码是:

void main(){
    struct jpeg_compress_struct cinfo;
    struct jpeg_error_mgr jerr;
    cinfo.err = jpeg_std_error(&jerr);
    jpeg_create_compress(&cinfo);
    FILE* outfile = fopen("/tmp/test.jpeg", "wb");
    jpeg_stdio_dest(&cinfo, outfile);

    //cinfo.image_width      = xinfo.width;
    //cinfo.image_height     = xinfo.height;
    //cinfo.input_components = 3;
    //cinfo.in_color_space   = JCS_RGB;

    jpeg_set_defaults(&cinfo);
    /*set the quality [0..100]  */
    jpeg_set_quality (&cinfo, 75, true);
    jpeg_start_compress(&cinfo, true);
    jpeg_finish_compress(&cinfo);
}

我采取并从另一个站点进行了一些更改。

虽然如您所见,Xinfo 不存在,在那个例子中我发现它是一个截图库或其他东西。

所以我只是想给它一个我在硬盘上得到的图像并压缩它。不想让它变得比必要的更难。

http://www.andrewewhite.net/wordpress/2008/09/02/very-simple-jpeg-writer-in-cc/

4

0 回答 0