Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 Praktikum13
- {
- public partial class Form1 : Form
- {
- List<Bitmap> objBitmap = new List<Bitmap>();
- Bitmap objBitmap1;
- Bitmap objBitmap2;
- Bitmap objBitmap3;
- Bitmap objBitmap4;
- int jumlahImage = 0;
- public Form1()
- {
- InitializeComponent();
- }
- private void LoadImage1_Click(object sender, EventArgs e)
- {
- DialogResult d = openFileDialog1.ShowDialog();
- if (d == DialogResult.OK)
- {
- objBitmap1 = new Bitmap(openFileDialog1.FileName);
- pictureBox1.Image = objBitmap1;
- }
- }
- private void LoadImage2_Click(object sender, EventArgs e)
- {
- DialogResult d = openFileDialog1.ShowDialog();
- if (d == DialogResult.OK)
- {
- objBitmap2 = new Bitmap(openFileDialog1.FileName);
- pictureBox2.Image = objBitmap2;
- }
- }
- private int[] hitungHX(Bitmap objBitmap)
- {
- objBitmap3 = new Bitmap(objBitmap);
- int[] hx = new int[objBitmap.Height];
- int counter = 0;
- for (int y = 0; y < objBitmap.Height; y++)
- {
- for (int x = 0; x < objBitmap.Width; x++)
- {
- Color w = objBitmap.GetPixel(x, y);
- if (w.R == 0) counter++;
- }
- hx[y] = counter;
- counter = 0;
- }
- return hx;
- }
- private int[] hitungHY(Bitmap objBitmap)
- {
- objBitmap3 = new Bitmap(objBitmap);
- int[] hy = new int[objBitmap.Width];
- int counter = 0;
- for (int x = 0; x < objBitmap.Width; x++)
- {
- for (int y = 0; y < objBitmap.Height; y++)
- {
- Color w = objBitmap.GetPixel(x, y);
- if (w.R == 0) counter++;
- }
- hy[x] = counter;
- counter = 0;
- }
- return hy;
- }
- private int selisih(int[] hx1, int[]hy1, int[]hx2, int[]hy2)
- {
- int r = 0;
- for (int i = 0; i < hx1.Length; i++)
- r = r + (Math.Abs(hx1[i] - hx2[i]));
- for (int i = 0; i < hy1.Length; i++)
- r = r + (Math.Abs(hy1[i] - hy2[i]));
- return r;
- }
- private void btnSelisih_Click(object sender, EventArgs e)
- {
- int[] hx1 = hitungHX(objBitmap1);
- int[] hx2 = hitungHX(objBitmap2);
- int[] hy1 = hitungHY(objBitmap1);
- int[] hy2 = hitungHY(objBitmap2);
- labelSelisih.Text = "Selisih = " + selisih(hx1, hy1,hx2, hy2);
- }
- private void btnLoadImage_Click(object sender, EventArgs e)
- {
- DialogResult d = openFileDialog1.ShowDialog();
- if (d == DialogResult.OK)
- {
- Bitmap obj = new Bitmap(openFileDialog1.FileName);
- objBitmap.Add(obj);
- jumlahImage += 1;
- jmlImage.Text = "Jumlah Gambar : "+ jumlahImage.ToString();
- PictureBox pb = new PictureBox();
- pb.SizeMode = PictureBoxSizeMode.StretchImage;
- pb.Height = 100;
- pb.Width = 100;
- pb.Image = obj;
- flowLayoutPanel1.Controls.Add(pb);
- }
- }
- private void btnLoadImageBanding_Click(object sender, EventArgs e)
- {
- DialogResult d = openFileDialog1.ShowDialog();
- if (d == DialogResult.OK)
- {
- objBitmap4 = new Bitmap(openFileDialog1.FileName);
- pictureBox3.Image = objBitmap4;
- }
- }
- private void btnBanding_Click(object sender, EventArgs e)
- {
- int[] hx = hitungHX(objBitmap4);
- int[] hy = hitungHY(objBitmap4);
- int[] hslSelisih = new int[jumlahImage];
- for (int i = 0; i < jumlahImage; i++)
- {
- int[] hx1 = hitungHX(objBitmap[i]);
- int[] hy1 = hitungHY(objBitmap[i]);
- hslSelisih[i] = selisih(hx, hy, hx1, hy1);
- }
- //mengurutkan data ranking
- int[] values = new int[jumlahImage];
- for (int i = 0; i < jumlahImage; i++)
- {
- values[i] = i;
- }
- //melakukan sorting
- Array.Sort(hslSelisih, values);
- foreach (int key in hslSelisih)
- {
- Console.Write(key);
- Console.Write(' ');
- }
- Console.WriteLine();
- foreach (int value in values)
- {
- Console.Write(value);
- Console.Write(' ');
- }
- Console.WriteLine();
- //menampilkan data hasil
- flowLayoutPanel2.Controls.Clear();
- for (int i = 0; i < jumlahImage; i++)
- {
- FlowLayoutPanel panel = new FlowLayoutPanel();
- panel.Height = 130;
- panel.Width = 110;
- panel.AutoScroll = true;
- panel.FlowDirection = FlowDirection.BottomUp;
- PictureBox pb = new PictureBox();
- pb.SizeMode = PictureBoxSizeMode.StretchImage;
- pb.Height = 100;
- pb.Width = 100;
- pb.Image = objBitmap[values[i]];
- Label lb = new Label();
- lb.Text = "Selisih : " + hslSelisih[i];
- panel.Controls.Add(pb);
- panel.Controls.Add(lb);
- flowLayoutPanel2.Controls.Add(panel);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment