安装のlibjpeg:須藤はapt-getをインストールのlibjpeg-devの
デモ
#include <iostreamの> する#include <jpeglib.h> の#include <memory.h> する#include <stdio.hに> する#include <STDLIB.H> INT readJpegFromFile(CONST のchar * input_filename、符号なしのchar *&output_buffer) { 構造体 jpeg_decompress_struct CINFO; // JPEG压缩结构構造体jpeg_error_mgr jerr。 FILE * INPUT_FILE。 // 输入文件 JSAMPARRAYバッファ; int型row_width; // unsigned char型* output_buffer。 符号なしのchar * TMP = NULL; cinfo.err = jpeg_std_error(&Jerr); // 開いている入力ファイル IF((= INPUT_FILEのfopen(input_filename、" RB "))== NULL) { fprintfの(stderrに、" を開けません%S \ N- " 、input_filename); } // 初期化JPEG圧縮構造 jpeg_create_decompress(&CINFO); // データ・ソース・ファイル・セット (&jpeg_stdio_srcをCINFO、INPUT_FILE); // セットJPEGは、読み取りヘッド (ボイド)jpeg_read_header(&CINFO)、TRUE。 // データをデコードを開始 (無効)jpeg_start_decompress(&CINFO)。 std :: coutの << " 输出一些图像的信息:" << はstd ::てendl; std :: coutの << " 幅:" << cinfo.image_width << はstd ::てendl; std :: coutの << " 身長:" << cinfo.image_height << はstd ::てendl; std :: coutの << " 色彩空间:" << cinfo.jpeg_color_space << はstd ::てendl; std :: coutの << " 颜色通道数:" << cinfo.num_components <<" << cinfo.image_width * cinfo.image_height * cinfo.output_components << はstd ::てendl; int型のバイト= cinfo.image_width * cinfo.image_height * cinfo.output_components; // 行宽度 row_width = cinfo.output_width * cinfo.output_components。// RGBRGB // 跳过头文件字节 バッファ=(* cinfo.mem-> alloc_sarray)((j_common_ptr)&CINFO、JPOOL_IMAGE、row_width、1 ); output_buffer =(符号なしCHAR *)はmalloc(row_width * cinfo.output_height)。 // 初始化为0 のmemset(output_buffer、0、row_width * cinfo.output_height)。 TMP= output_buffer。 // 读取数据行扫描 一方(cinfo.output_scanline < cinfo.output_height) { (ボイド)jpeg_read_scanlines(&CINFO、緩衝液、1 )。 memcpy(TMP、 * バッファ、row_width)。 TMP + = row_width。 } (ボイド)jpeg_finish_decompress(&CINFO)。 // 关闭文件 fcloseを(INPUT_FILE)。 返すバイト。 } int型のmain() { のstd :: coutの << " こんにちは、世界!"<< はstd ::てendl; 符号なしのchar * imgdata = NULL; readJpegFromFile(" 7.jpg " 、imgdata)。 printf(" 地址:%pを\ N "、&imgdata)。 もし(!imgdata = NULL) { 無料(imgdata)。 } 戻り 0 。 }