C Read colors from Bitmap -


im'm loading color of pixel , writes one-byte variable. when want read color (for red pixel) should result: 255 however, value is: 4294967296. follows value has been recorded in 32-byte variable. why happen?

struct rgbpix{  char r;  char g;  char b; }typedef rgb; 

...

rgb **data=(rgb **)malloc(sizeof(rgb *)*picture.biwidth);     for(i = 0; < picture.biwidth; i++){         data[i] = (rgb*) malloc(sizeof(rgb) *picture.biheight);     } 

...

for(i=0;i<picture.biwidth;i++){         for(j=0;j<picture.biheight;j++){          fread(&data[i][j].r, 1, 1,bmpfile);         fread(&data[i][j].g, 1, 1,bmpfile);         fread(&data[i][j].b, 1, 1,bmpfile);         }      }     printf("%ld", data[0][1].r); 

char appears signed type on machine. use unsigned char avoid sign extension.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -