本文介绍了C ++重新presenting在一维数组三维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要的漂浮字节值存储在pixelsArray为每个3D坐标,以一维数组:

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 char[HEIGHT*WIDTH*3];

for (int i = 0; i < HEIGHT; i++)
{
   for (int j = 0; j < WIDTH; j++)
   {
      for (int k = 0; k < 3; k++)
      {
         pixelsArray[?] = aFloat;
      }
   }
}

会去什么的?我想这也需要有 +的sizeof(浮动)某处索引,如果我没有记错。

What would go in the ?? I think it also needs to have + sizeof(float) somewhere in the index if I'm not mistaken.

推荐答案

您内线需要是:

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

这应该给你一个全白图像。

This should give you an all-white image.

请确保您的目标是每个像素真正三个字节而不是四(Alpha通道或填充);如果是四,你只需要改变 3 上面一个 4

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.

这篇关于C ++重新presenting在一维数组三维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 10:38