Monday, 20 November 2017

C# Generate Image Noise

public Bitmap GenerateNoise(int width, int height)
{
     Bitmap finalBmp = new Bitmap(width, height);
     Random r = new Random();

     for (int x = 0; x < width; x++)
     {
          for (int y = 0; y < height; y++)
          {
               int num = r.Next(0, 256);
               finalBmp.SetPixel(x, y, Color.FromArgb(255, num, num, num));
          }
     }

     return finalBmp;
}

No comments:

Post a Comment