Search code examples
c#wpfimagepixel

Image draw pixel by pixel from double array


I am trying to achieve something but after hours of search, I decided just to ask the more experienced. I am reading a pgm file(grayscale image represented with the value of gray for every pixel) and loading it into double array => data[,]. I am trying to make a double loop that will fill an image object in WPF window with the correct grayscale value for every pixel.

Here is my need more code-like represented:

int[,] data = new int[img.width,img.height];` 
for(int i=0; i<img.Height;i++)`
{
    for(int j=0; j<img.Width;j++)
    {
        //line that will fill image with pixel[i,j];
    }

} 

Solution

  • Have a look at the example provided by microsoft on MSDN:

    http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.setpixel(v=vs.110).aspx