C# make black and white pictures

Posted: October 8, 2014 in C#
Tags: ,

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;

namespace WindowsFormsApplication20
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{

string file_path = string.Empty;
Bitmap bayram = null;

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
file_path = openFileDialog1.FileName;

bayram = new Bitmap(file_path);

pictureBox1.Image = bayram;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}

for (int y = 0; y < bayram.Height; y++)
{
for (int x = 0; x < bayram.Width; x++)
{
Color old = bayram.GetPixel(x, y);
int average = (old.R + old.G + old.B) / 3;
Color new1 = Color.FromArgb(old.A, average, average, average);
bayram.SetPixel(x, y, new1);
}
}
pictureBox1.Image = bayram;

}
}
}

———————————————————————————————————————–

Orjinal görüntü:

images (1)

Daha sonraki görüntü:

14

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s