C# Script Aplikasi Filter Foto Visual Studio 2015:
Script:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Bitmap img, img2, imgneg, imggrey, imgclip, imgsep;
private void button3_Click(object sender, EventArgs e)
{
imgneg = new Bitmap(img);
for (int a = 0; a < imgneg.Width; a++)
for (int b = 0; b < imgneg.Height; b++)
{
Color c2 = imgneg.GetPixel(a, b);
//pemfilteran negative dengan rumus ketetapan dimana pemfilteran dilakukan disetiap segmen warna (R,G, dan B) dengan variabel integer baru intensitas warna RGB r2, g2, b2
int r2 = 255 - c2.R; int g2 = 255 - c2.G; int b2 = 255 - c2.B;
// setting per pixel citra dengan isi warna sesuai dengan sampling warna pixel yang sudah difilter negative R,G, dan B nya dengan koordinat pixel sesuai dengan pengulangan terus menerus yakni variabel koordinat a dan b sampai pengulangan terhenti
imgneg.SetPixel(a, b, Color.FromArgb(r2, g2, b2));
}
//setting picturebox gambar_hasil sesuai dengan hasil gambar yang telah di filter negative warna citra pada setiap pixel gambar dari picturebox gambar_awal
pictureBox2.Image = imgneg;
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
}
public Form1()
{
InitializeComponent();
}
private void pictureBox11_Click(object sender, EventArgs e)
{
this.Close();
}
private void button5_Click(object sender, EventArgs e)
{
imgclip = new Bitmap(img);
for (int c = 0; c < imgclip.Width; c++)
for (int d = 0; d < imgclip.Height; d++)
{
Color c3 = imgclip.GetPixel(c, d);
//pemfilteran clipping dengan rumus ketetapan dimana pemfilteran dilakukan disetiap segmen warna (R,G, dan B) dengan variabel integer baru intensitas warna RGB r3, g3, b3 untuk pemfilteran clipping menggunakan seleksi intensitas maksimum dan minimun dari warna pixel citra yang disampling untuk mengubah warna asli menjadi warna hasil pemfilteran clipping
int r3 = c3.R;
if (r3 > 127) { r3 = 255; }
else if (r3 < 127) { r3 = 0; }
int g3 = c3.G;
if (g3 > 127) { g3 = 255; }
else if (g3 < 127) { g3 = 0; }
int b3 = c3.B;
if (b3 > 127) { b3 = 255; }
else if (b3 < 127) { b3 = 0; }
imgclip.SetPixel(c, d, Color.FromArgb(r3, g3, b3));
}
pictureBox2.Image = imgclip;
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
}
private void button6_Click(object sender, EventArgs e)
{
SaveFileDialog f = new SaveFileDialog();
f.Filter = "Image File (.jpg)|.jpg;";
if (f.ShowDialog() == DialogResult.OK)
{
pictureBox2.Image.Save(f.FileName);
}
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button7_Click(object sender, EventArgs e)
{
imgsep = new Bitmap(img);
for (int y = 0; y < imgsep.Width; y++)
for (int z = 0; z < imgsep.Height; z++)
{
Color c5 = imgsep.GetPixel(y, z);
int a = c5.A;
int r = c5.R;
int g = c5.G;
int b = c5.B;
int tr = (int)(0.393 * r + 0.769 * g + 0.189 * b);
int tg = (int)(0.349 * r + 0.686 * g + 0.168 * b);
int tb = (int)(0.272 * r + 0.534 * g + 0.131 * b);
if (tr > 255)
{
r = 255;
}
else
{
r = tr;
}
if (tg > 255)
{
g = 255;
}
else
{
g = tg;
}
if (tb > 255)
{
b = 255;
}
else
{
b = tb;
}
imgsep.SetPixel(y, z, Color.FromArgb(a, r, g, b));
}
pictureBox2.Image = imgsep;
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
}
private void pictureBox13_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
private void button4_Click(object sender, EventArgs e)
{
imggrey = new Bitmap(img);
for (int f = 0; f < imggrey.Width; f++)
for (int g = 0; g < imggrey.Height; g++)
{
Color c1 = imggrey.GetPixel(f, g);
int r1 = c1.R; int g1 = c1.G; int b1 = c1.B; int gray = (byte)(.299 * r1 + .587 * g1 + .114 * b1);
r1 = gray; g1 = gray; b1 = gray;
// setting per pixel citra dengan isi warna sesuai dengan sampling warna pixel yang sudah difilter grayscale R,G, dan B nya dengan koordinat pixel sesuai dengan pengulangan terus menerus yakni variabel koordinat f dan g sampai pengulangan terhenti
imggrey.SetPixel(f, g, Color.FromArgb(r1, g1, b1));
}
//setting picturebox gambar_hasil sesuai dengan hasil gambar yang telah di filter negative warna citra pada setiap pixel gambar dari picturebox gambar_awal
pictureBox2.Image = imggrey;
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
}
private void button2_Click(object sender, EventArgs e)
{
int i, j, rata, nGreen, nRed, nBlue;
if (img != null)
{
img2 = new Bitmap(img);
for (i = 0; i <= img2.Width - 1; i++)
{
for (j = 0; j <= img2.Height - 1; j++)
{
Color pixelColor = img2.GetPixel(i, j);
nRed = pixelColor.R;
nGreen = pixelColor.G;
nBlue = pixelColor.B;
rata = Convert.ToInt32((nRed + nBlue + nGreen) / 3);
if (rata > 127)
rata = 255;
else
rata = 0;
Color newpixelColor = Color.FromArgb(rata, rata, rata);
img2.SetPixel(i, j, newpixelColor);
}
}
pictureBox2.Image = img2;
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
}
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog oFile = new OpenFileDialog();
oFile.Filter = "Image File (*.bmp,*.jpg,*.png)|*.bmp;*.jpg;*.png";
if (oFile.ShowDialog() == DialogResult.OK)
{
img = new Bitmap(new Bitmap(oFile.FileName));
pictureBox1.Image = img;
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Bitmap img, img2, imgneg, imggrey, imgclip, imgsep;
private void button3_Click(object sender, EventArgs e)
{
imgneg = new Bitmap(img);
for (int a = 0; a < imgneg.Width; a++)
for (int b = 0; b < imgneg.Height; b++)
{
Color c2 = imgneg.GetPixel(a, b);
//pemfilteran negative dengan rumus ketetapan dimana pemfilteran dilakukan disetiap segmen warna (R,G, dan B) dengan variabel integer baru intensitas warna RGB r2, g2, b2
int r2 = 255 - c2.R; int g2 = 255 - c2.G; int b2 = 255 - c2.B;
// setting per pixel citra dengan isi warna sesuai dengan sampling warna pixel yang sudah difilter negative R,G, dan B nya dengan koordinat pixel sesuai dengan pengulangan terus menerus yakni variabel koordinat a dan b sampai pengulangan terhenti
imgneg.SetPixel(a, b, Color.FromArgb(r2, g2, b2));
}
//setting picturebox gambar_hasil sesuai dengan hasil gambar yang telah di filter negative warna citra pada setiap pixel gambar dari picturebox gambar_awal
pictureBox2.Image = imgneg;
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
}
public Form1()
{
InitializeComponent();
}
private void pictureBox11_Click(object sender, EventArgs e)
{
this.Close();
}
private void button5_Click(object sender, EventArgs e)
{
imgclip = new Bitmap(img);
for (int c = 0; c < imgclip.Width; c++)
for (int d = 0; d < imgclip.Height; d++)
{
Color c3 = imgclip.GetPixel(c, d);
//pemfilteran clipping dengan rumus ketetapan dimana pemfilteran dilakukan disetiap segmen warna (R,G, dan B) dengan variabel integer baru intensitas warna RGB r3, g3, b3 untuk pemfilteran clipping menggunakan seleksi intensitas maksimum dan minimun dari warna pixel citra yang disampling untuk mengubah warna asli menjadi warna hasil pemfilteran clipping
int r3 = c3.R;
if (r3 > 127) { r3 = 255; }
else if (r3 < 127) { r3 = 0; }
int g3 = c3.G;
if (g3 > 127) { g3 = 255; }
else if (g3 < 127) { g3 = 0; }
int b3 = c3.B;
if (b3 > 127) { b3 = 255; }
else if (b3 < 127) { b3 = 0; }
imgclip.SetPixel(c, d, Color.FromArgb(r3, g3, b3));
}
pictureBox2.Image = imgclip;
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
}
private void button6_Click(object sender, EventArgs e)
{
SaveFileDialog f = new SaveFileDialog();
f.Filter = "Image File (.jpg)|.jpg;";
if (f.ShowDialog() == DialogResult.OK)
{
pictureBox2.Image.Save(f.FileName);
}
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button7_Click(object sender, EventArgs e)
{
imgsep = new Bitmap(img);
for (int y = 0; y < imgsep.Width; y++)
for (int z = 0; z < imgsep.Height; z++)
{
Color c5 = imgsep.GetPixel(y, z);
int a = c5.A;
int r = c5.R;
int g = c5.G;
int b = c5.B;
int tr = (int)(0.393 * r + 0.769 * g + 0.189 * b);
int tg = (int)(0.349 * r + 0.686 * g + 0.168 * b);
int tb = (int)(0.272 * r + 0.534 * g + 0.131 * b);
if (tr > 255)
{
r = 255;
}
else
{
r = tr;
}
if (tg > 255)
{
g = 255;
}
else
{
g = tg;
}
if (tb > 255)
{
b = 255;
}
else
{
b = tb;
}
imgsep.SetPixel(y, z, Color.FromArgb(a, r, g, b));
}
pictureBox2.Image = imgsep;
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
}
private void pictureBox13_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
private void button4_Click(object sender, EventArgs e)
{
imggrey = new Bitmap(img);
for (int f = 0; f < imggrey.Width; f++)
for (int g = 0; g < imggrey.Height; g++)
{
Color c1 = imggrey.GetPixel(f, g);
int r1 = c1.R; int g1 = c1.G; int b1 = c1.B; int gray = (byte)(.299 * r1 + .587 * g1 + .114 * b1);
r1 = gray; g1 = gray; b1 = gray;
// setting per pixel citra dengan isi warna sesuai dengan sampling warna pixel yang sudah difilter grayscale R,G, dan B nya dengan koordinat pixel sesuai dengan pengulangan terus menerus yakni variabel koordinat f dan g sampai pengulangan terhenti
imggrey.SetPixel(f, g, Color.FromArgb(r1, g1, b1));
}
//setting picturebox gambar_hasil sesuai dengan hasil gambar yang telah di filter negative warna citra pada setiap pixel gambar dari picturebox gambar_awal
pictureBox2.Image = imggrey;
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
}
private void button2_Click(object sender, EventArgs e)
{
int i, j, rata, nGreen, nRed, nBlue;
if (img != null)
{
img2 = new Bitmap(img);
for (i = 0; i <= img2.Width - 1; i++)
{
for (j = 0; j <= img2.Height - 1; j++)
{
Color pixelColor = img2.GetPixel(i, j);
nRed = pixelColor.R;
nGreen = pixelColor.G;
nBlue = pixelColor.B;
rata = Convert.ToInt32((nRed + nBlue + nGreen) / 3);
if (rata > 127)
rata = 255;
else
rata = 0;
Color newpixelColor = Color.FromArgb(rata, rata, rata);
img2.SetPixel(i, j, newpixelColor);
}
}
pictureBox2.Image = img2;
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
}
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog oFile = new OpenFileDialog();
oFile.Filter = "Image File (*.bmp,*.jpg,*.png)|*.bmp;*.jpg;*.png";
if (oFile.ShowDialog() == DialogResult.OK)
{
img = new Bitmap(new Bitmap(oFile.FileName));
pictureBox1.Image = img;
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
}
}
}
0 komentar:
Posting Komentar