/************************************************* * Protanomaly Color Blindness Simulator * * I.e., UltraMuffin's first brave experiment * * in writing a program with Microsoft Visual C#. * * * * This code was developed with Visual C# 2008 * * Express Edition, which is free, so you have no * * excuse not to learn! * *************************************************/ using System; using System.Drawing; using System.Windows.Forms; class MyForm : Form { private Button button1; private Image myImage, cloneImage; private Bitmap myBitmap, cloneBitmap; private PictureBox pictureBox1 = new PictureBox(); public MyForm() { Text = "Protanomaly Color Blindness Simulator"; InitializeComponent(); } [STAThreadAttribute] public static void Main() { MyForm aForm = new MyForm(); Application.Run(aForm); } private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); this.button1.Location = new System.Drawing.Point(350, 400); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = "Load File"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(775, 450); this.Controls.Add(this.button1); this.Name = "MyForm"; this.ResumeLayout(false); } private void draw_jpg(object sender, PaintEventArgs e) { Point myPoint = new Point(25, 25); Point otherPoint = new Point(400, 25); System.Console.WriteLine(this.ClientSize); Size mySize = new Size(350, 350); Size otherSize = new Size(350, 350); Rectangle myRectangle = new Rectangle(myPoint, mySize); Rectangle otherRectangle = new Rectangle(otherPoint, otherSize); Graphics g = e.Graphics; g.DrawImage(myBitmap, myRectangle); g.DrawImage(cloneBitmap, otherRectangle); } private void button1_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp"; if (open.ShowDialog() == DialogResult.OK) { myImage = Image.FromFile(open.FileName); cloneImage = Image.FromFile(open.FileName); myBitmap = myImage as Bitmap; cloneBitmap = cloneImage as Bitmap; for (int i = 0; i < myBitmap.PhysicalDimension.Width; i++) { for (int j = 0; j < myBitmap.PhysicalDimension.Height; j++) { int red, green, blue; red = myBitmap.GetPixel(i, j).R; green = myBitmap.GetPixel(i, j).G; blue = myBitmap.GetPixel(i, j).B; red *= (int) 0.25; Color newColor = Color.FromArgb(red, green, blue); cloneBitmap.SetPixel(i, j, newColor); } } this.Paint += new PaintEventHandler(this.draw_jpg); this.Invalidate(); } } }