I'm trying to read in the pixel data from a bitmap. The following code is supposed to display:
FF00 FFFFFF 00 00FF 0FF0 00
instead it displays this:
FF 0 0 FF FF FF 0 0 0 FF 0 F0 F 0 0 0
I can't find the problem, tracing the code looks okay, so I'm thinking it is the location variable, but so far, no luck. The solution should have only FF and 0, not F0 and F.
https://github.com/josheirm/BitmapExpander2/tree/branch7
Thanks!
do {
memset(dest2, 0x00, 100);
memset(dest, 0x00, 100);
int answer = 0;
//set of three values
if (counter == 0 || counter == 1 )
{
file = fopen("b.bmp", "r");
fseek(file, location, SEEK_SET);
answer = fgetc(file);
if (feof(file)) {
fclose(file);
break;
}
sprintf(dest, "%X", answer);
strcpy(dest2, dest);
location++;
answer = fgetc(file);
if (feof(file)) {
fclose(file);
break;
}
sprintf(dest, "%X", answer);
strcat(dest2, dest);
location++;
answer = fgetc(file);
if (feof(file)) {
fclose(file);
break;
}
fclose(file);
sprintf(dest, "%X", answer);
strcat(dest2, dest);
counter++;
location++;
decimal = hexadecimalToDecimal(dest2);
file = fopen("C:/Users/joshe/file7", "a");
//set of three data
fwrite(&decimal, 3, 1, file);
fclose(file);
}
//set of two values
else if (counter == 2)
{
memset(dest2, 0x00, 100);
memset(dest, 0x00, 100);
file = fopen("b.bmp", "r");
fseek(file, location, SEEK_SET);
answer = fgetc(file);
if (feof(file)) {
fclose(file);
break;
}
sprintf(dest, "%X", answer);
strcpy(dest2, dest);
location++;
answer = fgetc(file);
if (feof(file)) {
fclose(file);
break;
}
fclose(file);
sprintf(dest, "%X", answer);
strcat(dest2, dest);
counter = 0;
location++;
decimal = hexadecimalToDecimal(dest2);
file = fopen("C:/Users/joshe/file7", "a");
//set of two data
fwrite(&decimal, 2, 1, file);
fclose(file);
}
} while(1);