C++ Representing a 3D array in a 1D array

后端 未结 2 1070
甜味超标
甜味超标 2021-01-05 13:02

I want to store the byte value of aFloat in pixelsArray for each 3D coordinate, in a 1D array:

float aFloat = 1.0;
unsigned char* pixelsArray = new unsigned          


        
2条回答
  •  一个人的身影
    2021-01-05 13:19

    Your inside line needs to be:

    pixelsArray[(i * WIDTH + j) * 3 + k] = (unsigned char)(255.0 * aFloat);
    

    This should give you an all-white image.

    Make sure your target is really three bytes per pixel and not four (alpha channel or padding); if it is four, you'll just need to change the 3 above to a 4.

提交回复
热议问题