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
Post a Comment