How to get the width/height of jpeg file without using library?

后端 未结 7 1515
清歌不尽
清歌不尽 2020-12-25 08:43

Firstly I want to say I tried many times to find the answer by using google search, and I found many results but I did not understand, because I don\'t know the idea of read

相关标签:
7条回答
  • 2020-12-25 09:17

    then you have to find hight and width marker of jpeg that is [ffc0].

    after finding ffc0 in binary formate, the the four,five bytes are hight and six and seven bytes are width.

    eg: [ff c0] d8 c3 c2 [ff da] [00 ff]
                          |         |
                          |         |
                          ->height  ->width
    
    int position;
    unsigned char len_con[2];
    /*Extract start of frame marker(FFC0) of width and hight and get the position*/
    for(i=0;i<FILE_SIZE;i++)
    {
        if((image_buffer[i]==FF) && (image_buffer[i+1]==c0) )
        {
            position=i;
        }
    }
    /*Moving to the particular byte position and assign byte value to pointer variable*/
    position=position+5;
    *height=buffer_src[position]<<8|buffer_src[position+1];
    *width=buffer_src[position+2]<<8|buffer_src[position+3];
    
    printf("height %d",*height);
    printf("width %d",*width);
    
    0 讨论(0)
提交回复
热议问题