Search code examples
c++cimage-processingvisual-c++windows-ce

How to open and read 16 bit .raw file Vc++ (Wince platform)


I am trying to read the 16 bit .raw file using c++ (visual studio 2013) on Wince platform. but not sure about the api which should i use for open and read operation. Its seems file operation on image file is different than .txt file. Please help me for sample code to read 16 Bit raw data.


Solution

  • Addressing the C tag:
    Note: The following works well in C, and will also compile in (but is not optimal for) c++.

    If coding in C, then using fopen(,) is a good option, and the 2nd argument is key as it sets the function to perform several variations of opening a file, including binary reads. The following excerpt is one of several sections provided in the C Tutorial – Binary File I/O:

    #include<stdio.h>
    
    /* Our structure */
    struct rec
    {
        int x,y,z;
    };
    
    int main()
    {
        int counter;
        FILE *ptr_myfile;
        struct rec my_record;
    
        ptr_myfile=fopen("test.bin","rb");//note the argument 'rb' for read binary
        if (!ptr_myfile)
        {
            printf("Unable to open file!");
            return 1;
        }
        for ( counter=1; counter <= 10; counter++)
        {
            fread(&my_record,sizeof(struct rec),1,ptr_myfile);
            printf("%d\n",my_record.x);
        }
        fclose(ptr_myfile);
        return 0;
    }