2

I'm a little confused about the byte[] array output from the Android camera. A picture is essentially a 2D array, so why is the output only 1D?

I'm trying to take the byte array output and perform a Fourier transform on it, and for that to happen I need the data to be in a 2D double array. So how do I get from the camera output byte array to a 2D double array?

Thanks

0

1 Answer 1

2

The 1D array is flattened 2D array. To convert it to 2D array, you need something like this:

double[][] array2D = new double[width][height];

for(int i = 0 ; i < array2D.length ; i++)
{
    for(int j = 0 ; j < array2D[i].length ; i++)
    {
        array2D[i][j] = array1D[i * array2D.length + j];
    }
}

Width and height might be other way round.

Sign up to request clarification or add additional context in comments.

1 Comment

I've been using Toast to print out the size of the byte array...the size changes every time. Sometimes its 413128, other times its 611611, or other numbers in between, so I don't get how this answer can possibly work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.