3.laporan pencit rgb

11
LAPORAN PENGOLAHAN CITRA NAMA : AFVRIONA ERSA FAHIRA NRP/KELAS : 3110121033 / 3MKB TANGGAL : 7 OKTOBER 2014 1. PENGOLAHAN RGB A. LISTING PROGRAM 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; 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); 1

Upload: ersa-pevensie

Post on 23-Dec-2015

234 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 3.Laporan Pencit Rgb

LAPORAN PENGOLAHAN CITRA

NAMA : AFVRIONA ERSA FAHIRA

NRP/KELAS : 3110121033 / 3MKB

TANGGAL : 7 OKTOBER 2014

1. PENGOLAHAN RGB A. LISTING PROGRAM

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;

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++)

1

Page 2: 3.Laporan Pencit Rgb

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

Page 3: 3.Laporan Pencit Rgb

D. GAMBAR HASIL LISTING

3

Page 4: 3.Laporan Pencit Rgb

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

B. GAMBAR HASIL LISTING

4

Page 5: 3.Laporan Pencit Rgb

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

B. GAMBAR HASIL LISTING- GREY SCALE RED

5

Page 6: 3.Laporan Pencit Rgb

- GREY SCALE GREEN

- GREY SCALE BLUE

6

Page 7: 3.Laporan Pencit Rgb

4. MEMBACA DAN MENYIMPAN FILE GAMBAR A. LISTING PROGRAM

//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) {

File.Save(saveFileDialog1.FileName, ImageFormat.Jpeg); } }

B. PERTANYAAN

- Pada komponen PictureBox, terdapat segitiga kecil di

bagian kanan atas yang digunakan untuk mengubah

size-mode. Jelaskan apa perbedaan masing-masing size-

mode:

a. Normal -> gambar akan ditampilkan sebagian saja yaitu diambil dari pojok kiri atas dan memiliki ukuran sama dengan luas picture box.

b. StrechtImage -> gambar akan ditampilkan menyesuaikan dengan luas picturebox yang telah dibuat.

c. AutoSize -> gambar akan ditampilkan sesuai dengan ukuran gambar yang sebenarnya, tidak menyesuaikan dengan luas picturebox.

d. CenterImage -> gambar akan ditampilkan sebagian saja yaitu diambil dari tengah gambar dan memiliki ukuran sama dengan luas picture box

e. Zoom -> gambar aka ditampilakan sesuai dengan luas picturebox. Namun berukuran lebih besar dari mode StrechImage.

- Jelaskan apa fungsi dari perintah pictureBox1.Image = File;

-> berfungsi untuk menyatakan bahwa gambar pada picturebox1 berasal dari file yang akan di load.

7

Page 8: 3.Laporan Pencit Rgb

5. MEMBACA DATA PROGRAM A. LISTING PROGRAM

//LOAD GAMBAR 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; } }

//COPY GAMBAR 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; }

//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

8

Page 9: 3.Laporan Pencit Rgb

2. Flip horizontal

3. Flip vertikal

9