嗨,我有一个从QNetworkReply获得的jpeg图像的QByteArray。我到处都看到从文件读取并解压缩的jpeg图像,
FILE * infile;
......
if ((infile = fopen(filename, "rb")) == NULL)
{
fprintf(stderr, "can't open %s\n", filename);
exit(1);
}
jpeg_stdio_src(&cinfo, infile);
jpeg_read_header(&cinfo, 0);
jpeg_start_decompress(&cinfo);
然后
while (scan lines remain to be read)
jpeg_read_scanlines(...);
但是,如何从QByteArray而不是文件/ stdio流读取它?
最佳答案
用
void jpeg_mem_src(j_decompress_ptr cinfo, unsigned char * inbuffer,
unsigned long insize);
代替
jpeg_stdio_src
QByteArray qarr;
jpeg_decompress_struct cinfo;
jpeg_mem_src(&cinfo, qarr.data(), qarr.size());
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
/// etc..