int width = 50; 
int height = 50; 
var bitmap = new Bitmap(width, height, PixelFormat.Canonical);
 
for (int y = 0; y < height; y++)
   for (int x = 0; x < width; x++)
   {
      int red = 0; 
      int green = 0; 
      int blue = 0; 
      bitmap.SetPixel(x, y, Color.FromArgb(0, red, green, blue));
   }

********************************************************************************************************

 private void button1_Click(object sender, EventArgs e)
        {
            Bitmap bmp = new Bitmap(700, 550);                      //改图只显示最近输入的700个点的数据曲线。
          //  Graphics graphics = Graphics.FromImage(bmp);
         //   SolidBrush brush1 = new SolidBrush(Color.FromArgb(255, 0, 0));
         //   graphics.FillRectangle(brush1, 0, 0, 700, 550);//Brushes.Sienna
            for(int i =0;i<bmp.Width;i++)
                for(int j =0 ;j<bmp.Height;j++)
                {
                    Color c = Color.FromArgb( (i/400)*255, (j/300)*255, 0);
                    bmp.SetPixel(i, j, c);
                }
            bmp.Save("c:\\11.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);//指定图片格式   
            bmp.Dispose();
        //    graphics.Dispose();
        //    brush1.Dispose();//一定释放内存。
        }



本文转载:CSDN博客