Tag Archives: Visual Studio 2012

Manipulasi RGB dengan Visual Studio 2012

Code :

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 Image3
{
public partial class Form1 : Form
{
Bitmap objBitmap1;
Bitmap objBitmap2;
Bitmap objBitmap3;
Bitmap objBitmap4;
Bitmap objBitmap5;
Bitmap objBitmap6;
Bitmap objBitmap7;
Bitmap objBitmap8;
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 wb = w.B;
Color new_w = Color.FromArgb(wb, wb, wb);
objBitmap3.SetPixel(x, y, new_w);
}
pictureBox3.Image = objBitmap3;
}
}

private void Form1_Load(object sender, EventArgs e)
{

}

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;
}
}

private void button6_Click(object sender, EventArgs e)
{
objBitmap5 = 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);
objBitmap5.SetPixel(x, y, new_w);
}
pictureBox6.Image = objBitmap5;
}
}

private void button5_Click(object sender, EventArgs e)
{
objBitmap6 = 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, wr, wr);
objBitmap6.SetPixel(x, y, new_w);
}
pictureBox5.Image = objBitmap6;
}
}

private void button7_Click(object sender, EventArgs e)
{
objBitmap7 = 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(wg, wg, wg);
objBitmap7.SetPixel(x, y, new_w);
}
pictureBox7.Image = objBitmap7;
}
}

private void button8_Click(object sender, EventArgs e)
{
objBitmap8 = 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;
int r,g,b;
if (2 * wr < 255)
{
r = 2 * wr;
}
else
{
r = 255;
}
if ((18 / 10) * wr < 255)
{
g = (18 / 10) * wr;
}
else
{
g = 255;
}
b = wr;
Color new_w = Color.FromArgb(r,g,b);
objBitmap8.SetPixel(x, y, new_w);
}
pictureBox8.Image = objBitmap8;
}
}
}
}

Out put :

Visual studio 2012

Dari program di atas kita menampilkan Layer Red, Green dan Blue, selain itu kita juga menampilkan Grayscale Red, Green, Blue.

pada setiap layer kita hanya menampilkan sisi warna tipe layer pada setiap pixelnya, sehingga hasil nya seperti di atas. seperti ini “Color new_w = Color.FromArgb(wb, wb, wb)”

pada gray scale kita hanya merubah bagian RGB tertentu menjadi warna RGB tipe gray scale dan yang lain nya menjadi 0. seperti ini “Color new_w = Color.FromArgb(0, 0, wb)”

Fungsi Setpixel dan Getpixel untuk Copy dan Flip Citra menggunakan Visual Studio 2012

Code :

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 Image2
{
public partial class Form1 : Form
{
Bitmap objBitmap;
Bitmap objBitmap1;
Bitmap objBitmap2;
Bitmap objBitmap3;
Bitmap objBitmap4;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click (object sender, EventArgs e)
{
DialogResult d = openFileDialog1.ShowDialog();
if (d == DialogResult.OK)
{
objBitmap = new Bitmap(openFileDialog1.FileName);
pictureBox1.Image = objBitmap;
}
}

private void button2_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, y, w);
}
pictureBox2.Image = objBitmap1;
}
}

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;
}
}

private void button4_Click(object sender, EventArgs e)
{
objBitmap2 = 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);
objBitmap2.SetPixel(x, objBitmap.Height – 1 – y, w);
}
pictureBox3.Image = objBitmap2;
}
}

private void label2_Click(object sender, EventArgs e)
{

}

private void label1_Click(object sender, EventArgs e)
{

}

private void pictureBox2_Click(object sender, EventArgs e)
{

}

private void button5_Click(object sender, EventArgs e)
{
objBitmap3 = new Bitmap(objBitmap.Height, objBitmap.Width);
for (int x = 0; x < objBitmap.Width; x++)
{
for (int y = 0; y < objBitmap.Height; y++)
{
//int a = x;
Color w = objBitmap.GetPixel(x, y);
objBitmap3.SetPixel(objBitmap.Height – 1 – y, x, w);
}
pictureBox4.Image = objBitmap3;
}
}

private void button6_Click(object sender, EventArgs e)
{
objBitmap4 = 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);
objBitmap4.SetPixel(objBitmap.Width – 1 – x, objBitmap.Height – 1 – y, w);
}
pictureBox5.Image = objBitmap4;
}
}
}

Out put :

Visual Studio 2012

jadi dari program dan output di atas, kita melakukan flip Horizontal, Vertical, Rotate 90 dan Rotate 180. kita melakukan program tersebut memindahkan setiap pixel RGB nya. ehehehhe 🙂