Mega Code Archive

 
Categories / C# / 2D Graphics
 

Write the pixel information to the console window

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; public class Form1 : Form {     protected override void OnPaint(PaintEventArgs e) {     Graphics gForm = e.Graphics;     gForm.FillRectangle(Brushes.White, this.ClientRectangle);     Bitmap bmp = new Bitmap(6, 6);     Graphics gBmp = Graphics.FromImage(bmp);     gBmp.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);     gBmp.DrawLine(Pens.Red, 0, 0, 5, 5);     gForm.DrawImage(bmp, 20, 20, bmp.Width, bmp.Height);          for (int y = 0; y < bmp.Height; ++y)     {       for (int x = 0; x < bmp.Width; ++x)       {         Color c = bmp.GetPixel(x, y);         Console.Write("{0,2:x}{1,2:x}{2,2:x}{3,2:x}  ",c.A, c.R, c.G, c.G);       }       Console.WriteLine();     }     bmp.Dispose();     }     public static void Main() {         Application.Run(new Form1());     } }