Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C “错误解释JPEG图像文件(无效的JPEG文件结构:SOS在SOF之前)”是什么意思?_C_Jpeg_Cs50 - Fatal编程技术网

C “错误解释JPEG图像文件(无效的JPEG文件结构:SOS在SOF之前)”是什么意思?

C “错误解释JPEG图像文件(无效的JPEG文件结构:SOS在SOF之前)”是什么意思?,c,jpeg,cs50,C,Jpeg,Cs50,我试图从一个.raw文件中恢复JPG,当我试图从我的程序输出中打开.JPG时,它给出了错误,或者它说了一些奇怪的十六进制,并说它是JPEG不受支持的标记类型,但它说它是JPG!。我做错了什么 * * Recovers JPEGs from a forensic image. */ //0xff 0xd8 0xff 0xe0 //0xff 0xd8 0xff 0xe1 #define BLOCK 512 #define START1END 0xe0 #define START

我试图从一个.raw文件中恢复JPG,当我试图从我的程序输出中打开.JPG时,它给出了错误,或者它说了一些奇怪的十六进制,并说它是JPEG不受支持的标记类型,但它说它是JPG!。我做错了什么

     *
 * Recovers JPEGs from a forensic image.
 */

 //0xff 0xd8 0xff 0xe0
 //0xff 0xd8 0xff 0xe1

#define BLOCK 512
#define START1END 0xe0
#define START2END 0xe1

#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <stdint.h>


//sets the begins or jpgs
uint8_t checkjpg1[4] = {0xff, 0xd8, 0xff, 0xe0};
uint8_t checkjpg2[4] = {0xff, 0xd8, 0xff, 0xe1};

//making variables
int found = 0; 
char title[BLOCK];
FILE* img;
int ifopen = 1;


int main(int argc, char* argv[])
{
    //opening file
    FILE* inptr = fopen("card.raw", "r");
    //checking if file opening failed
    if (inptr == NULL)
    {
        return 2;
    }

    //making buffer
    unsigned char buffer[BLOCK];

    //going through the file
    while(fread(&buffer,sizeof(char),BLOCK,inptr) == BLOCK)
    {
         //checking if begin == the possible begin of jpg    
         if ((buffer[0] == checkjpg1[0] && buffer[1] == checkjpg1[1] && buffer[2] == checkjpg1[2]) && 
         (buffer[3] == checkjpg1[3] || buffer[3] == checkjpg2[3]))
         {
            //if a jpg is not open
            if (ifopen == 1)
            {
                //make one
                found+=1;
                sprintf(title,"00%d.jpg",found);
                img = fopen(title,"a");
                if(buffer[3] == checkjpg1[3])
                {
                    fwrite(&checkjpg1,sizeof(char),4,img);
                }

            }
            else//else
            {
                //end the one and open new one
                fclose(img);
                found +=1;
                sprintf(title,"00%d.jpg",found);
                img = fopen(title,"a");
                if(buffer[3] == checkjpg1[3])
                {
                    fwrite(&checkjpg2,sizeof(char),4,img);
                }
            }
         }
         else if (img != NULL)
         {
            fwrite(buffer,sizeof(char),BLOCK,img);
         }
     }

    fclose(inptr);
}

帧的开始定义了图像的结构。扫描开始标记包含压缩图像数据。为了扩展压缩数据,您需要知道图像SOF的大小


听起来您的流缺少SOF标记。

它只是说该文件实际上不是JPEG文件。扫描开始当然不能出现在帧开始之前。而且,一个.raw文件永远不是jpeg文件,它使用特定于供应商的格式,并且包含未压缩的数据。你需要另一个库,比如libraw。谢谢,但是为什么我的程序失败了呢。如果它说它不是JPEG文件,那就好了。我想把JPG从原料上去掉。为什么它不起作用呢?我将JPG的适当开端写入当前img。我只是不明白为什么它不承认它是JPG;失败?我要检查它是否等于NULL吗?