Oleh :
FIGA COSPININGRUM TITO PUTRI
NIM. G41202131
3. Buat tampilan form seperti ini dengan cara memasukkan toolbox lalu disusun dengan rapi
Berikut adalah Toolbox yang digunakan:
4. Lalu kita ubah Name masing-masing pictureBox dan button pada Properties menjadi
pictureBox1 = picOriginal
pictureBox2 = picRed
pictureBox3 = picGreen
pictureBox4 = picBlue
button1 = btnLoad
5. Double klik pada button Load Image maka akan terbuka lembar kerja Coding
Agar tombol Load Image dapat berfungsi, masukkan kode berikut ini:
String imgLocation = "";
try
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "jpg files(*.jpg)|*.jpg| png files(*.png) | *.png |
all files(*.*) | *.* ";
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
imgLocation = dialog.FileName;
picOriginal.ImageLocation = imgLocation;
Bitmap bmp = new Bitmap(imgLocation);
int w = bmp.Width;
int h = bmp.Height;
Bitmap bmpR = new Bitmap(bmp);
Bitmap bmpG = new Bitmap(bmp);
Bitmap bmpB = new Bitmap(bmp);
// red green blue image
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
// get pixel value
Color p = bmp.GetPixel(x, y);
// extract argb
int a = p.A;
int r = p.R;
int g = p.G;
int b = p.B;
// set red image
bmpR.SetPixel(x, y, Color.FromArgb(a, r,
0, 0));
// set green image
bmpG.SetPixel(x, y, Color.FromArgb(a, 0,
g, 0));
// set blue image
bmpB.SetPixel(x, y, Color.FromArgb(a, 0,
0, b));
}
}
picRed.Image = bmpR;
picGreen.Image = bmpG;
picBlue.Image = bmpB;
}
}
catch (Exception)
{
MessageBox.Show("Img Error", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
6. Klik Run untuk menjalankan program. Jika sudah berhasil, klik tombol Load Image
untuk memasukkan gambar dari library komputer. Maka akan muncul Output seperti ini: