开发者

how can I convert Image to 2 dimensional Array in c#

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


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;
}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜