无法在 Qt 中导入 jpeg 文件
我的任务是在 Qt 中实现 JPEG 编码器/解码器。我必须处理 jpeg 标记(例如 0xFFC4,它是霍夫曼表的开头)和标记之间的数据。我使用 QFile 类打开 jpeg 文件。调试时结果如下图所示。正如您所看到的,marker[0] 中的值为 -1/255,marker[1] 中的值为 -40/216,而 if 语句永远不会为 true 我不知道为什么?代码如下:
try{
char markers[2];
char TableData[64];
QFile *file= new QFile( "NovaSlika.jpeg");
if(file->open(QFile::ReadOnly )){
while(file->read((char*)markers,sizeof(markers))){
if(markers[0]=='255' && markers[1]=='216'){//FF i C4
char TableLength[2];
char tableMetaData;
file->read((char*)TableLength,sizeof(TableLength));//Read table length
file->read((char*)tableMetaData,sizeof(tableMetaData));//Read metadata
file->read((char*)TableData,sizeof(TableData));//Read data
break;
}
}
}
调试过程图片这里
My task is to implement JPEG encoder/decoder in Qt. I have to process jpeg markers (for example 0xFFC4 which is start of huffman table) and data between markers. I open my jpeg file using QFile class. While debugging the result is shown in picture bellow. As you can see the value in marker[0] is -1/255 and marker[1] is -40/216, and the if statement is never true I don't know why? The code is following:
try{
char markers[2];
char TableData[64];
QFile *file= new QFile( "NovaSlika.jpeg");
if(file->open(QFile::ReadOnly )){
while(file->read((char*)markers,sizeof(markers))){
if(markers[0]=='255' && markers[1]=='216'){//FF i C4
char TableLength[2];
char tableMetaData;
file->read((char*)TableLength,sizeof(TableLength));//Read table length
file->read((char*)tableMetaData,sizeof(tableMetaData));//Read metadata
file->read((char*)TableData,sizeof(TableData));//Read data
break;
}
}
}
Picture of debugging process is here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意您的 while 条件: read()
你可能应该这样做:
而且这一行也不正确:
去掉那些单引号。 (-GCC 上的墙会警告你这一点)。应该是:
Be careful in your while condition: read() returns
You should probably do:
And this line isn't right either:
Get rid of those single quotes. (-Wall on gcc would have warned you on this). It should be: