Hi everybody, I wrote a function, which I already talked of here, that should save in an array each pixel value of a bmp image file, but now I have a new problem. If I give to my function a path for a bmp image I made by myself I get as depth value '0', instead of '8', that is the depth value I saved my image with. But if I try to read this value on an image not made by me, it's alright. Can anybody help me?
This is my code function:
void get_pixels(char path[]){
FILE *fp;
int i, j=0, dim=0, count=0;
int offset;
unsigned char depth=NULL;
char bmp[5];
fp = fopen(path, "rb");
for(i=strlen(path)-4;i<strlen(path);i++){
bmp[j]=path[i];
j++;
}
if(strstr(bmp, ".bmp")==NULL){
printf("\nIndicare un file .bmp come immagine!\n");
exit(1);
}
fseek(fp, 28, SEEK_SET);
fread(&depth, sizeof(depth), 1, fp);
printf("\n%d", depth);
if(depth!=8){
printf("\nSelezionare una immagine a 8 bit!\n");
exit(2);
}
fseek(fp, 10, SEEK_SET);
fread(&offset, sizeof(offset), 1, fp);
dim=(4-(ima_lar % 4))+ima_lar;
j=0;
fseek(fp, offset, SEEK_SET);
for(i=0;i<ima_alt*dim;i++){
if(count!=ima_lar){
fread(&pixels[j], sizeof(char), 1, fp);
printf("\n%d: %d", j+1, pixels[j]);
j++;
count++;
}else{
fseek(fp, 1, SEEK_CUR);
count=0;
}
}
fclose(fp);
}
path is passed to the function in a for cicle, through a string array in the form of 'filenames[i]'.