Professional Documents
Culture Documents
1. PENGOLAHAN RGB
A. LISTING PROGRAM
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Image File;
Bitmap objBitmap1;
Bitmap objBitmap2;
Bitmap objBitmap3;
Bitmap objBitmap4;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult d = openFileDialog1.ShowDialog();
if (d == DialogResult.OK)
{
objBitmap1 = new Bitmap(openFileDialog1.FileName);
pictureBox1.Image = objBitmap1;
}
}
private void button2_Click(object sender, EventArgs e)
{
objBitmap2 = new Bitmap(objBitmap1);
for(int x=0; x<objBitmap1.Width; x++)
for(int y=0; y<objBitmap1.Height; y++)
{
Color w = objBitmap1.GetPixel(x, y);
int wr = w.R;
Color new_w = Color.FromArgb(wr, 0, 0);
objBitmap2.SetPixel(x, y, new_w);
}
pictureBox2.Image=objBitmap2;
}
private void button3_Click(object sender, EventArgs e)
{
objBitmap3 = new Bitmap(objBitmap1);
for (int x = 0; x < objBitmap1.Width; x++)
for (int y = 0; y < objBitmap1.Height; y++)
{
Color w = objBitmap1.GetPixel(x, y);
int wg = w.G;
Color new_w = Color.FromArgb(0, wg, 0);
objBitmap3.SetPixel(x, y, new_w);
}
pictureBox3.Image = objBitmap3;
}
private void button4_Click(object sender, EventArgs e)
{
objBitmap4 = new Bitmap(objBitmap1);
for (int x = 0; x < objBitmap1.Width; x++)
for (int y = 0; y < objBitmap1.Height; y++)
{
Color w = objBitmap1.GetPixel(x, y);
int wb = w.B;
Color new_w = Color.FromArgb(0, 0, wb);
objBitmap4.SetPixel(x, y, new_w);
}
pictureBox4.Image = objBitmap4;
}
}
}
B. FOM LISTING
C. FOM DESIGN
2. SEPIA
A. LISTING PROGRAM
//SEPHIA
private void button9_Click(object sender, EventArgs e)
{
objBitmap1 = new Bitmap(objBitmap);
int a, b;
for (int x = 0; x < objBitmap.Width; x++)
for (int y = 0; y < objBitmap1.Height; y++)
{
Color w = objBitmap.GetPixel(x, y);
int r = w.R;
if (2 * r <= 255)
a = 2 * r;
else
a = 255;
if ((int)1.8 * r <= 255)
b = (int)1.8 * r;
else
b = 255;
Color wb = Color.FromArgb(a, b, r);
objBitmap1.SetPixel(x, y, wb);
}
pictureBox2.Image = objBitmap1;
}
3. GRAYSCALE
A. LISTING PROGRAM
//GREYSCALE RED
private void button6_Click(object sender, EventArgs e)
{
objBitmap1 = new Bitmap(objBitmap);
for (int x = 0; x < objBitmap.Width; x++)
for (int y = 0; y < objBitmap1.Height; y++)
{
Color w = objBitmap.GetPixel(x, y);
int r = w.R;
Color wb = Color.FromArgb(r, r, r);
objBitmap1.SetPixel(x, y, wb);
}
pictureBox2.Image = objBitmap1;
}
//GREYSCALE GREEN
private void button7_Click(object sender, EventArgs e)
{
objBitmap1 = new Bitmap(objBitmap);
for (int x = 0; x < objBitmap.Width; x++)
for (int y = 0; y < objBitmap1.Height; y++)
{
Color w = objBitmap.GetPixel(x, y);
int g = w.G;
Color wb = Color.FromArgb(g, g, g);
objBitmap1.SetPixel(x, y, wb);
}
pictureBox2.Image = objBitmap1;
}
//GREYSCALE BLUE
private void button8_Click(object sender, EventArgs e)
{
objBitmap1 = new Bitmap(objBitmap);
for (int x = 0; x < objBitmap.Width; x++)
for (int y = 0; y < objBitmap1.Height; y++)
{
Color w = objBitmap.GetPixel(x, y);
int b = w.B;
Color wb = Color.FromArgb(b, b, b);
objBitmap1.SetPixel(x, y, wb);
}
pictureBox2.Image = objBitmap1;
}
//OPEN FILE
private void button1_Click(object sender, EventArgs e)
{
DialogResult d = openFileDialog1.ShowDialog();
if (d == DialogResult.OK)
{
File = Image.FromFile(openFileDialog1.FileName);
pictureBox1.Image = File;
}
}
//SAVE FILE
private void button2_Click(object sender, EventArgs e)
{
DialogResult d = saveFileDialog1.ShowDialog();
if (d == DialogResult.OK)
6
{
File.Save(saveFileDialog1.FileName, ImageFormat.Jpeg);
}
}
B. PERTANYAAN
digunakan
untuk
mengubah
{
Color w = objBitmap.GetPixel(x, y);
objBitmap1.SetPixel(x, y, w);
}
pictureBox2.Image = objBitmap1;
}
//FLIP HORIZONTAL
private void button3_Click(object sender, EventArgs e)
{
objBitmap1 = new Bitmap(objBitmap);
for (int x = 0; x < objBitmap.Width; x++)
for (int y = 0; y < objBitmap.Height; y++)
{
Color w = objBitmap.GetPixel(x, y);
objBitmap1.SetPixel(objBitmap.Width - 1 - x, y, w);
}
pictureBox2.Image = objBitmap1;
}
//FLIP VERTICAL
private void button4_Click(object sender, EventArgs e)
{
objBitmap1 = new Bitmap(objBitmap);
for (int x = 0; x < objBitmap.Width; x++)
for (int y = 0; y < objBitmap.Height; y++)
{
Color w = objBitmap.GetPixel(x, y);
objBitmap1.SetPixel(x, objBitmap.Height - 1 - y, w);
}
pictureBox2.Image = objBitmap1;
}
B. GAMBAR HASIL EDIT
1. Copy image
2. Flip horizontal
3. Flip vertikal
8