私は、ファイルに書き込むためのlibjpegを使用してこの機能を発見した:私は実際に時間を節約するために、それをファイルに保存せず、単にメモリバッファにJPEG圧縮された画像を作成する必要がありますでしょうlibjpegでファイルの代わりにメモリバッファに書き込みますか?
int write_jpeg_file(char *filename)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
/* this is a pointer to one row of image data */
JSAMPROW row_pointer[1];
FILE *outfile = fopen(filename, "wb");
if (!outfile)
{
printf("Error opening output jpeg file %s\n!", filename);
return -1;
}
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, outfile);
/* Setting the parameters of the output file here */
cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = bytes_per_pixel;
cinfo.in_color_space = color_space;
/* default compression parameters, we shouldn't be worried about these */
jpeg_set_defaults(&cinfo);
/* Now do the compression .. */
jpeg_start_compress(&cinfo, TRUE);
/* like reading a file, this time write one row at a time */
while(cinfo.next_scanline < cinfo.image_height)
{
row_pointer[0] = &raw_image[ cinfo.next_scanline * cinfo.image_width * cinfo.input_components];
jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
/* similar to read file, clean up after we're done compressing */
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
fclose(outfile);
/* success code is 1! */
return 1;
}
を。誰かが私にそれを行う方法の例を教えてもらえますか?
私はしばらくWebを検索していましたが、もしあれば、やっぱり難しい例もあります。
私は、これらの関数ポインタが 'jpeg_stdio_dest'に影響すると思いますか? –
@Ben Voigt、 'jpeg_stdio_dest'へのソースを見ています。構造体を割り当てて 'cinfo-> dest'にセットし、ポインタを設定します。私は自分のサンプルコードが 'jpeg_destination_mgr'構造体を作成しないので少し不完全かもしれないと思っていますが、後でそれを見ていきます。 –
もちろん、ああ。関数ポインタの直後に、グローバル変数は必要ありません(自分自身のデータ( 'std :: vector')を格納することができます。](http://blogs.msdn.com/b/oldnewthing/archive/2010/12/20/ 10107027.aspx)。 –