c++ fopen 返回一个带有的文件 *
我从 libjpeg 示例复制了这段代码,并将其传递给标准文件;
FILE *soureFile;
if ((soureFile = fopen(sourceFilename, "rb")) == NULL)
{
fprintf(stderr, "can't open %s\n", sourceFilename);
exit(1);
}
jpeg_stdio_src(&jpegDecompress, soureFile);
jpeg_read_header(&jpegDecompress, true);
它会导致文件指针不包含任何信息,因此会在最后一行因访问冲突而中断。 有任何想法吗?
编辑:根据托比亚斯的建议,fopen 确实可以正常打开文件,但 jpeg_read_header 又会失败,并且仍然存在访问冲突。
编辑:经过更多挖掘
ijg 支持 JPEG - 获取访问冲突
I copied this code from the libjpeg example and im passing it standard files;
FILE *soureFile;
if ((soureFile = fopen(sourceFilename, "rb")) == NULL)
{
fprintf(stderr, "can't open %s\n", sourceFilename);
exit(1);
}
jpeg_stdio_src(&jpegDecompress, soureFile);
jpeg_read_header(&jpegDecompress, true);
It results in a file pointer that contains no information and therefore breaks on the last line with access violations.
Any ideas?
EDIT: On Tobias' advice the fopen does appear to open the file ok but the jpeg_read_header is in turn failing with the access violation still.
EDIT: After a little more digging
JPEG support with ijg - getting access violation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 strerror 或 perror 获取确切原因:
Use strerror or perror to get exact reason:
“
select
未损坏” 。如果
fopen
返回了一个有效的文件指针,并且jpeg_read_header
无法使用它,则表明这两个语句之间有人对其做了坏事。两者之间唯一的一个是 jpg_stdio_src 调用,如果满足所有先决条件,该调用就不会失败。
底线:了解
jpg_stdio_src
失败的原因。 我的猜测:它需要使用jpeg_create_decompress
宏。"
select
isn't broken".If
fopen
returned a valid file pointer, andjpeg_read_header
can't use it, someone between those two statements has done something bad to it.The only one in between is the
jpg_stdio_src
call, which wouldn't fail if all it's preconditions are fulfilled.Bottom line: see why
jpg_stdio_src
fails. My guess: it needs to be constructed using thejpeg_create_decompress
macro.