开发者

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

开发者 https://www.devze.com 2023-02-09 12:00 出处:网络
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

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

精彩评论

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

关注公众号