1

I have image in C# and I created array of that but for filtering and mask the picture I need 2 dimensional Array of image thank for your help!

user605738
  • 11
  • 1
  • 2
  • Can you show how you have created a mono dimensional array from your image? Please tell us more also about what image format you are using. – Davide Piras Feb 06 '11 at 23:25
  • Do the inverse of this? http://stackoverflow.com/questions/638701/how-to-create-an-image-from-a-2-dimensional-byte-array – OJ. Feb 06 '11 at 23:31

1 Answers1

1

Creating a 2d array from your image, or from your 1d array, is pretty straightforward. Here is the way to do it from your 1d array, although this can be easily translated directly to your image code:

int[][] To2dArray(int[] source, int width) 
{
    int height = source.Length / width;
    int[][] result = new int[height][width];
    for(int i = 0; i < height; i++)
    {
        for(int j = 0; j < width; j++)
        {
            result[i][j] = source[i * width + j];
        }
    }
    return result;
}

Darkhydro
  • 1,992
  • 4
  • 24
  • 43