Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

The answer to this question herehere should help explain how to use the GetData function.

Basically, the data is stored in the return array from the GetData call is formed by reading the 2D texture from left to right, top to bottom, transforming it as follows:

AAAA
BBBB  => AAAABBBBCCCCDDDD
CCCC
DDDD

To determine where a given pixel in the 1D array is, we use the index calculation of i + (j * width) should return the correct pixel at any given point.

Your assumptions is almost correct, you are just forgetting to take the width into account. Basically, multiply the Y coord (your j value) by the width of the Texture to select the correct start of the index block containing your pixel, then add the X coord (your i value) to select the correct pixel from that block.

In the sample above, assuming we want the value at (1,2), we have the following equation.

v = i + (j * width)
v = 1 + (2 * 4)
v = 1 + 8
v = 9
item at offset 9 = C

On 2nd though, that first link probably isn't the best, its just the first one I found with the required math. Here's another one that describes (sortof) how to use it.

The answer to this question here should help explain how to use the GetData function.

Basically, the data is stored in the return array from the GetData call is formed by reading the 2D texture from left to right, top to bottom, transforming it as follows:

AAAA
BBBB  => AAAABBBBCCCCDDDD
CCCC
DDDD

To determine where a given pixel in the 1D array is, we use the index calculation of i + (j * width) should return the correct pixel at any given point.

Your assumptions is almost correct, you are just forgetting to take the width into account. Basically, multiply the Y coord (your j value) by the width of the Texture to select the correct start of the index block containing your pixel, then add the X coord (your i value) to select the correct pixel from that block.

In the sample above, assuming we want the value at (1,2), we have the following equation.

v = i + (j * width)
v = 1 + (2 * 4)
v = 1 + 8
v = 9
item at offset 9 = C

On 2nd though, that first link probably isn't the best, its just the first one I found with the required math. Here's another one that describes (sortof) how to use it.

The answer to this question here should help explain how to use the GetData function.

Basically, the data is stored in the return array from the GetData call is formed by reading the 2D texture from left to right, top to bottom, transforming it as follows:

AAAA
BBBB  => AAAABBBBCCCCDDDD
CCCC
DDDD

To determine where a given pixel in the 1D array is, we use the index calculation of i + (j * width) should return the correct pixel at any given point.

Your assumptions is almost correct, you are just forgetting to take the width into account. Basically, multiply the Y coord (your j value) by the width of the Texture to select the correct start of the index block containing your pixel, then add the X coord (your i value) to select the correct pixel from that block.

In the sample above, assuming we want the value at (1,2), we have the following equation.

v = i + (j * width)
v = 1 + (2 * 4)
v = 1 + 8
v = 9
item at offset 9 = C

On 2nd though, that first link probably isn't the best, its just the first one I found with the required math. Here's another one that describes (sortof) how to use it.

Updated answer with more info
Source Link
Seta
  • 1.4k
  • 1
  • 10
  • 19

The answer to this question here should help explain how to use the GetData function.

Basically, the data is stored in the return array from the GetData call is readformed by reading the 2D texture from left to right, top to bottom, sotransforming it as follows:

AAAA
BBBB  => AAAABBBBCCCCDDDD
CCCC
DDDD

To determine where a given pixel in the 1D array is, we use the index calculation of Xi + (Yj * width) where X = i and Y = j should return the correct pixel at any given point.

Your assumptions is almost correct, you are just forgetting to take the width into account. Basically, multiply the Y co-ordcoord (your j value) by the width of the Texture to select the correct start of the index block containing your pixel, then add the X co-ordcoord (your i value) to select the correct pixel from that block.

In the sample above, assuming we want the value at (1,2), we have the following equation.

v = i + (j * width)
v = 1 + (2 * 4)
v = 1 + 8
v = 9
item at offset 9 = C

On 2nd though, that first link probably isn't the best, its just the first one I found with the required math. Here's another one that describes (sortof) how to use it.

The answer to this question here should help explain how to use the GetData function.

Basically, the data is stored in the return array is read from left to right, top to bottom, so the index calculation of X + (Y * width) where X = i and Y = j should return the correct pixel at any given point.

Your assumptions is almost correct, you are just forgetting to take the width into account. Basically, multiply the Y co-ord by the width of the Texture to select the correct start of the index block containing your pixel, then add the X co-ord to select the correct pixel from that block

The answer to this question here should help explain how to use the GetData function.

Basically, the data is stored in the return array from the GetData call is formed by reading the 2D texture from left to right, top to bottom, transforming it as follows:

AAAA
BBBB  => AAAABBBBCCCCDDDD
CCCC
DDDD

To determine where a given pixel in the 1D array is, we use the index calculation of i + (j * width) should return the correct pixel at any given point.

Your assumptions is almost correct, you are just forgetting to take the width into account. Basically, multiply the Y coord (your j value) by the width of the Texture to select the correct start of the index block containing your pixel, then add the X coord (your i value) to select the correct pixel from that block.

In the sample above, assuming we want the value at (1,2), we have the following equation.

v = i + (j * width)
v = 1 + (2 * 4)
v = 1 + 8
v = 9
item at offset 9 = C

On 2nd though, that first link probably isn't the best, its just the first one I found with the required math. Here's another one that describes (sortof) how to use it.

Source Link
Seta
  • 1.4k
  • 1
  • 10
  • 19

The answer to this question here should help explain how to use the GetData function.

Basically, the data is stored in the return array is read from left to right, top to bottom, so the index calculation of X + (Y * width) where X = i and Y = j should return the correct pixel at any given point.

Your assumptions is almost correct, you are just forgetting to take the width into account. Basically, multiply the Y co-ord by the width of the Texture to select the correct start of the index block containing your pixel, then add the X co-ord to select the correct pixel from that block