LAMPIRAN A SCREEN SHOOT
Gambar A.1 Screen Shoot Splash Screen
Gambar A.2 Screen Shoot Form Utama
A-1
Gambar A.3 Screen Shoot Form Dialog Konverter ke Biner
Gambar A.4 Screen Shoot Form Konverter ke Kode
A-2
Gambar A.5 Screen Shoot Form Klasifikasi
A-3
LAMPIRAN B LISTING PROGRAM
B.1 LISTING PROGRAM PADA FORM SPLASH 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 iCout_U____Does_it { public partial class frm_SPLASH : Form { public static frm_SPLASH _FormSPLASH = null; int _COUNTER; public frm_SPLASH() { InitializeComponent(); tmr_SPLASH.Enabled = true; _COUNTER = 0; } private void tmr_SPLASH_Tick(object sender, EventArgs e) { if (_COUNTER >= 100) { tmr_SPLASH.Enabled = false; frm_MAIN _UTAMA = new frm_MAIN(); _FormSPLASH = this; this.Hide(); _UTAMA.Show(); } else { _COUNTER++; prg_SPLASH.Value = _COUNTER; } }
B-1
} } B.2 LISTING PROGRAM PADA FORM UTAMA 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; using System.IO; namespace iCout_U____Does_it { public partial class frm_MAIN : Form { public static frm_MAIN saya = null; private string _PATH_DIR; public int[] _OBJECT_ID; public int[] _OBJECT_X_START; public int[] _OBJECT_X_END; public int[] _OBJECT_Y_START; public int[] _OBJECT_Y_END; public double[] _OBJECT_KELILING; public double[] _OBJECT_LUAS; public double[] _OBJECT_SHAPE; public int _JUMLAH; public int _TOLERANCE_PRI; public int _TOLERANCE_SLV; public int _JUMLAH_PRI; public int _JUMLAH_SLV; public int _ID_PRI; public int _ID_SLV; public frm_MAIN() { InitializeComponent();
B-2
deactivate_CONTROL(); } public void setJUMLAH_PRI(int _JUMLAH_PRIx) { _JUMLAH_PRI = _JUMLAH_PRIx; } public void setJUMLAH_SLV(int _JUMLAH_SLVx) { _JUMLAH_SLV = _JUMLAH_SLVx; } public void setTOLERANCE_PRI(int _TOLERANCE_PRIx) { _TOLERANCE_PRI = _TOLERANCE_PRIx; } public void setTOLERANCE_SLV(int _TOLERANCE_SLVx) { _TOLERANCE_SLV = _TOLERANCE_SLVx; } public void setID_PRI(int _ID_PRIx) { _ID_PRI = _ID_PRIx; } public void setID_SLV(int _ID_SLVx) { _ID_SLV = _ID_SLVx; } public void setOBJECT_ID(params int[] _OBJECT_IDx) { _OBJECT_ID = _OBJECT_IDx; } public void setOBJECT_X_START(params int[] _OBJECT_X_STARTx) { _OBJECT_X_START = _OBJECT_X_STARTx; } public void setOBJECT_Y_START(params int[] _OBJECT_Y_STARTx)
B-3
{ _OBJECT_Y_START = _OBJECT_Y_STARTx; } public void setOBJECT_X_END(params int[] _OBJECT_X_ENDx) { _OBJECT_X_END = _OBJECT_X_ENDx; } public void setOBJECT_Y_END(params int[] _OBJECT_Y_ENDx) { _OBJECT_Y_END = _OBJECT_Y_ENDx; } public void setOBJECT_KELILING(params double[] _OBJECT_KELILINGx) { _OBJECT_KELILING = _OBJECT_KELILINGx; } public void setOBJECT_LUAS(params double[] _OBJECT_LUASx) { _OBJECT_LUAS = _OBJECT_LUASx; } public void setOBJECT_SHAPE(params double[] _OBJECT_SHAPEx) { _OBJECT_SHAPE = _OBJECT_SHAPEx; } public void setJUMLAH(int _JUMLAHx) { _JUMLAH = _JUMLAHx; } private void deactivate_CONTROL() { cmd_CLOSE.Enabled = false; cmd_COLOR2GRAYSCALE.Enabled = false; cmd_COLOR2BINARY.Enabled = false; cmd_IMAGE2CODE.Enabled = false; cmd_LABELLING.Enabled = false; cmd_CLASSIFICATION.Enabled = false; cmd_REPORT.Enabled = false;
B-4
cmd_CLOSE.ForeColor = Color.Gray; cmd_COLOR2GRAYSCALE.ForeColor = Color.Gray; cmd_COLOR2BINARY.ForeColor = Color.Gray; cmd_IMAGE2CODE.ForeColor = Color.Gray; cmd_LABELLING.ForeColor = Color.Gray; cmd_CLASSIFICATION.ForeColor = Color.Gray; cmd_REPORT.ForeColor = Color.Gray; } private void activate_CONTROL() { cmd_CLOSE.Enabled = true; cmd_COLOR2GRAYSCALE.Enabled = true; cmd_COLOR2BINARY.Enabled = true; cmd_IMAGE2CODE.Enabled = true; cmd_LABELLING.Enabled = true; cmd_CLASSIFICATION.Enabled = true; cmd_REPORT.Enabled = true; cmd_CLOSE.ForeColor = Color.Black; cmd_COLOR2GRAYSCALE.ForeColor = Color.Black; cmd_COLOR2BINARY.ForeColor = Color.Black; cmd_IMAGE2CODE.ForeColor = Color.Black; cmd_LABELLING.ForeColor = Color.Black; cmd_CLASSIFICATION.ForeColor = Color.Black; cmd_REPORT.ForeColor = Color.Black; } private void cmd_EXIT_Click(object sender, EventArgs e) { this.Hide(); frm_SPLASH._FormSPLASH.Close(); } private void cmd_MINIMIZE_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } private void cmd_HELP_Click(object sender, EventArgs e) { MessageBox.Show("Sorry No Help Here !","iCount U!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation); }
B-5
private void cmd_NEW_Click(object sender, EventArgs e) { OpenFileDialog dlg_OPEN_PICTURE = new OpenFileDialog(); dlg_OPEN_PICTURE.Filter = "Bitmap Image|*.bmp"; dlg_OPEN_PICTURE.Title = "Select Bitmap Image File (BMP)"; dlg_OPEN_PICTURE.InitialDirectory = Application.StartupPath; dlg_OPEN_PICTURE.RestoreDirectory = false; dlg_OPEN_PICTURE.Multiselect = false; dlg_OPEN_PICTURE.FilterIndex = 0; dlg_OPEN_PICTURE.ShowDialog(); if (dlg_OPEN_PICTURE.FileName != "") { Bitmap _TMPGambar = new Bitmap(dlg_OPEN_PICTURE.FileName); pic_DISPLAY.Image = _TMPGambar; pic_DISPLAY.SizeMode = PictureBoxSizeMode.StretchImage; activate_CONTROL(); cmd_NEW.Enabled
= false;
cmd_NEW.ForeColor = Color.Gray; } cmd_CLOSE.Enabled = true; cmd_COLOR2GRAYSCALE.Enabled = true; cmd_COLOR2BINARY.Enabled =true; cmd_IMAGE2CODE.Enabled = false; cmd_LABELLING.Enabled = false; cmd_CLASSIFICATION.Enabled = false; cmd_REPORT.Enabled = false; cmd_CLOSE.ForeColor = Color.Black; cmd_COLOR2GRAYSCALE.ForeColor = Color.Black; cmd_COLOR2BINARY.ForeColor = Color.Black; cmd_IMAGE2CODE.ForeColor = Color.Gray; cmd_LABELLING.ForeColor = Color.Gray; cmd_CLASSIFICATION.ForeColor = Color.Gray; cmd_REPORT.ForeColor = Color.Gray; }
B-6
private void cmd_CLOSE_Click(object sender, EventArgs e) { cmd_NEW.Enabled = true; cmd_NEW.ForeColor = Color.Black; pic_DISPLAY.Image = iCout_U____Does_it.Properties.Resources.jpg_INITIAL; deactivate_CONTROL(); } private void cmd_COLOR2GRAYSCALE_Click(object sender, EventArgs e) { ImageProcessing Processing = new ImageProcessing(); Processing.setGAMBAR((Bitmap)(pic_DISPLAY.Image)); Processing.ConvertToGrayScale(); pic_DISPLAY.Image = (Bitmap)Processing.GAMBAR; pic_DISPLAY.SizeMode = PictureBoxSizeMode.StretchImage; cmd_CLOSE.Enabled = true; cmd_COLOR2GRAYSCALE.Enabled = false; cmd_COLOR2BINARY.Enabled = true; cmd_IMAGE2CODE.Enabled = false; cmd_LABELLING.Enabled = false; cmd_CLASSIFICATION.Enabled = false; cmd_REPORT.Enabled = false; cmd_CLOSE.ForeColor = Color.Black; cmd_COLOR2GRAYSCALE.ForeColor = Color.Gray; cmd_COLOR2BINARY.ForeColor = Color.Black; cmd_IMAGE2CODE.ForeColor = Color.Gray; cmd_LABELLING.ForeColor = Color.Gray; cmd_CLASSIFICATION.ForeColor = Color.Gray; cmd_REPORT.ForeColor = Color.Gray; } private void cmd_COLOR2BINARY_Click(object sender, EventArgs e) { saya = this;
B-7
frm_BINARY _frmBINARY = new frm_BINARY(); _frmBINARY.ShowDialog(); cmd_CLOSE.Enabled = false; cmd_COLOR2GRAYSCALE.Enabled = false; cmd_COLOR2BINARY.Enabled = false; cmd_IMAGE2CODE.Enabled = true; cmd_LABELLING.Enabled = false; cmd_CLASSIFICATION.Enabled = false; cmd_REPORT.Enabled = false; cmd_CLOSE.ForeColor = Color.Black; cmd_COLOR2GRAYSCALE.ForeColor = Color.Gray; cmd_COLOR2BINARY.ForeColor = Color.Gray; cmd_IMAGE2CODE.ForeColor = Color.Black; cmd_LABELLING.ForeColor = Color.Gray; cmd_CLASSIFICATION.ForeColor = Color.Gray; cmd_REPORT.ForeColor = Color.Gray; } private void cmd_IMAGE2CODE_Click(object sender, EventArgs e) { saya = this;
SaveFileDialog dlg_SAVE_CODE = new SaveFileDialog(); dlg_SAVE_CODE.Filter = "Plain Text File|*.wri"; dlg_SAVE_CODE.Title = "Save Plain Text Stream"; dlg_SAVE_CODE.ShowDialog(); dlg_SAVE_CODE.InitialDirectory = Application.StartupPath; dlg_SAVE_CODE.RestoreDirectory = false; if (dlg_SAVE_CODE.FileName != "") { frm_CODE _frmCODE = new frm_CODE(); _frmCODE.setPATH((string)dlg_SAVE_CODE.FileName); _frmCODE.setMODE("BINARY"); _frmCODE.ShowDialog(); } cmd_CLOSE.Enabled = false; cmd_COLOR2GRAYSCALE.Enabled = false;
B-8
cmd_COLOR2BINARY.Enabled = false; cmd_IMAGE2CODE.Enabled = false; cmd_LABELLING.Enabled = true; cmd_CLASSIFICATION.Enabled = false; cmd_REPORT.Enabled = false; cmd_CLOSE.ForeColor = Color.Black; cmd_COLOR2GRAYSCALE.ForeColor = Color.Gray; cmd_COLOR2BINARY.ForeColor = Color.Gray; cmd_IMAGE2CODE.ForeColor = Color.Gray; cmd_LABELLING.ForeColor = Color.Black; cmd_CLASSIFICATION.ForeColor = Color.Gray; cmd_REPORT.ForeColor = Color.Gray; } private void cmd_LABELLING_Click(object sender, EventArgs e) { saya = this; SaveFileDialog dlg_SAVE_LABELLING = new SaveFileDialog(); dlg_SAVE_LABELLING.Filter = "Plain Text File|*.wri"; dlg_SAVE_LABELLING.Title = "Save Plain Text Stream"; dlg_SAVE_LABELLING.ShowDialog(); dlg_SAVE_LABELLING.InitialDirectory = Application.StartupPath; dlg_SAVE_LABELLING.RestoreDirectory = false; if (dlg_SAVE_LABELLING.FileName != "") { frm_CODE _frmCODE = new frm_CODE(); _frmCODE.setPATH((string)dlg_SAVE_LABELLING.FileName); _frmCODE.setMODE("LABELLING"); _frmCODE.ShowDialog(); _PATH_DIR = (string)dlg_SAVE_LABELLING.FileName; } cmd_CLOSE.Enabled = false; cmd_COLOR2GRAYSCALE.Enabled = false; cmd_COLOR2BINARY.Enabled = false; cmd_IMAGE2CODE.Enabled = false; cmd_LABELLING.Enabled = false; cmd_CLASSIFICATION.Enabled = true;
B-9
cmd_REPORT.Enabled = false; cmd_CLOSE.ForeColor = Color.Black; cmd_COLOR2GRAYSCALE.ForeColor = Color.Gray; cmd_COLOR2BINARY.ForeColor = Color.Gray; cmd_IMAGE2CODE.ForeColor = Color.Gray; cmd_LABELLING.ForeColor = Color.Gray; cmd_CLASSIFICATION.ForeColor = Color.Black; cmd_REPORT.ForeColor = Color.Gray; } private void cmd_CLASSIFICATION_Click(object sender, EventArgs e) { saya = this; _PATH_DIR = Path.GetDirectoryName(_PATH_DIR) + "\\" + Path.GetFileNameWithoutExtension(_PATH_DIR) + ".icup"; frm_CLASSIFICATION _frmCLASS = new frm_CLASSIFICATION(); _frmCLASS.setJUMLAH(_JUMLAH); _frmCLASS.setOBJECT_ID(_OBJECT_ID); _frmCLASS.setOBJECT_X_START(_OBJECT_X_START); _frmCLASS.setOBJECT_Y_START(_OBJECT_Y_START); _frmCLASS.setOBJECT_X_END(_OBJECT_X_END); _frmCLASS.setOBJECT_Y_END(_OBJECT_Y_END); _frmCLASS.setOBJECT_KELILING(_OBJECT_KELILING); _frmCLASS.setOBJECT_LUAS(_OBJECT_LUAS); _frmCLASS.setOBJECT_SHAPE(_OBJECT_SHAPE); _frmCLASS.ShowDialog(); cmd_CLOSE.Enabled = false; cmd_COLOR2GRAYSCALE.Enabled = false; cmd_COLOR2BINARY.Enabled = false; cmd_IMAGE2CODE.Enabled = false; cmd_LABELLING.Enabled = false; cmd_CLASSIFICATION.Enabled = false; cmd_REPORT.Enabled = true; cmd_CLOSE.ForeColor = Color.Black; cmd_COLOR2GRAYSCALE.ForeColor = Color.Gray; cmd_COLOR2BINARY.ForeColor = Color.Gray; cmd_IMAGE2CODE.ForeColor = Color.Gray; cmd_LABELLING.ForeColor = Color.Gray;
B - 10
cmd_CLASSIFICATION.ForeColor = Color.Gray; cmd_REPORT.ForeColor = Color.Black; } private void cmd_REPORT_Click(object sender, EventArgs e) { saya = this; frm_REPORT _frmREPORT = new frm_REPORT();
_frmREPORT.ShowDialog(); } } }
B.3 LISTING PROGRAM PADA FORM BINARY 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 iCout_U____Does_it { public partial class frm_BINARY : Form { ImageProcessing Processing = new ImageProcessing(); private Bitmap _TMPGambar; public frm_BINARY() { InitializeComponent(); _TMPGambar = (Bitmap) frm_MAIN.saya.pic_DISPLAY.Image; }
B - 11
private void cmd_OK_Click(object sender, EventArgs e) { this.Close(); } private void cmd_CANCEL_Click(object sender, EventArgs e) { frm_MAIN.saya.pic_DISPLAY.Image = _TMPGambar; frm_MAIN.saya.pic_DISPLAY.SizeMode = PictureBoxSizeMode.StretchImage; this.Close(); } private void frm_BINARY_Load(object sender, EventArgs e) { if (chk_AUTOMATIC.Checked == true) { trc_TRESHOLD.Enabled = false; Processing.setGAMBAR(_TMPGambar); Processing.ConvertToBinaryAutomatic(); frm_MAIN.saya.pic_DISPLAY.Image = (Bitmap)Processing.GAMBAR; frm_MAIN.saya.pic_DISPLAY.SizeMode = PictureBoxSizeMode.StretchImage; } else { trc_TRESHOLD.Enabled = true; } trc_TRESHOLD.Value = 0; lbl_TRESHOLD.Text = "0"; } private void chk_AUTOMATIC_CheckedChanged(object sender, EventArgs e) { if (chk_AUTOMATIC.Checked == true) { trc_TRESHOLD.Enabled = false; Processing.setGAMBAR(_TMPGambar); Processing.ConvertToBinaryAutomatic();
B - 12
frm_MAIN.saya.pic_DISPLAY.Image = (Bitmap)Processing.GAMBAR; frm_MAIN.saya.pic_DISPLAY.SizeMode = PictureBoxSizeMode.StretchImage; } else { trc_TRESHOLD.Enabled = true; Processing.setGAMBAR(_TMPGambar); Processing.ConvertToBinaryManual(trc_TRESHOLD.Value); frm_MAIN.saya.pic_DISPLAY.Image = (Bitmap)Processing.GAMBAR; frm_MAIN.saya.pic_DISPLAY.SizeMode = PictureBoxSizeMode.StretchImage; lbl_TRESHOLD.Text = Convert.ToString(trc_TRESHOLD.Value); } trc_TRESHOLD.Value = 0; lbl_TRESHOLD.Text = "0"; } private void trc_TRESHOLD_Scroll(object sender, EventArgs e) { Processing.setGAMBAR(_TMPGambar); Processing.ConvertToBinaryManual(trc_TRESHOLD.Value); frm_MAIN.saya.pic_DISPLAY.Image = (Bitmap)Processing.GAMBAR; frm_MAIN.saya.pic_DISPLAY.SizeMode = PictureBoxSizeMode.StretchImage; lbl_TRESHOLD.Text = Convert.ToString(trc_TRESHOLD.Value); } } } B.4 LISTING PROGRAM PADA FORM CODE using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;
B - 13
using System.Linq; using System.Text; using System.Windows.Forms; namespace iCout_U____Does_it { public partial class frm_CODE : Form { private string _PATH; private string _MODE; private double _ZOOM; public frm_CODE() { InitializeComponent(); } public void setPATH(string _PATHx) { _PATH = _PATHx; } public void setMODE(string _MODEx) { _MODE = _MODEx; } private void frm_CODE_Load(object sender, EventArgs e) { ComputerVision Vision = new ComputerVision(); Vision.setGAMBAR((Bitmap)frm_MAIN.saya.pic_DISPLAY.Image); if (_MODE == "BINARY") { Vision.BINStreamText(_PATH); } else if (_MODE == "RGB") { Vision.RGBStreamText(_PATH); } else if (_MODE == "LABELLING") { Vision.LABStreamText(_PATH); } txt_CODE.LoadFile(_PATH, RichTextBoxStreamType.PlainText); _ZOOM = 1.0; } private void cmd_OK_Click(object sender, EventArgs e) {
B - 14
this.Close(); } private void cmd_ZOOM_IN_Click(object sender, EventArgs e) { _ZOOM = _ZOOM + 0.1; _ZOOM = (_ZOOM <= 1 ? 1 : _ZOOM); txt_CODE.ZoomFactor = Convert.ToSingle(_ZOOM); } private void cmd_ZOOM_OUT_Click(object sender, EventArgs e) { _ZOOM = _ZOOM - 0.1; _ZOOM = (_ZOOM <= 1 ? 1 : _ZOOM); txt_CODE.ZoomFactor = Convert.ToSingle(_ZOOM); } } } B.5 LISTING PROGRAM PADA FORM CLASSIFICATION using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Collections; using System.Xml; using System.IO; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace iCout_U____Does_it { public partial class frm_CLASSIFICATION : Form { private string _PATH; private int _JUMLAH; private int[] _OBJECT_ID; private int[] _OBJECT_X_START; private int[] _OBJECT_X_END; private int[] _OBJECT_Y_START;
B - 15
private int[] _OBJECT_Y_END; private double[] _OBJECT_KELILING; private double[] _OBJECT_LUAS; private double[] _OBJECT_SHAPE; public frm_CLASSIFICATION() { InitializeComponent(); } public void setPATH(string _PATHx) { _PATH = _PATHx; } public void setOBJECT_ID(params int[] _OBJECT_IDx) { _OBJECT_ID = _OBJECT_IDx; } public void setOBJECT_X_START(params int[] _OBJECT_X_STARTx) { _OBJECT_X_START = _OBJECT_X_STARTx; } public void setOBJECT_Y_START(params int[] _OBJECT_Y_STARTx) { _OBJECT_Y_START = _OBJECT_Y_STARTx; } public void setOBJECT_X_END(params int[] _OBJECT_X_ENDx) { _OBJECT_X_END = _OBJECT_X_ENDx; } public void setOBJECT_Y_END(params int[] _OBJECT_Y_ENDx) { _OBJECT_Y_END = _OBJECT_Y_ENDx; } public void setOBJECT_KELILING(params double[] _OBJECT_KELILINGx) { _OBJECT_KELILING = _OBJECT_KELILINGx; }
B - 16
public void setOBJECT_LUAS(params double[] _OBJECT_LUASx) { _OBJECT_LUAS = _OBJECT_LUASx; } public void setOBJECT_SHAPE(params double[] _OBJECT_SHAPEx) { _OBJECT_SHAPE = _OBJECT_SHAPEx; } public void setJUMLAH(int _JUMLAHx) { _JUMLAH = _JUMLAHx; } private void Processor() { double _TOLERANCE; double _TOLERANCE_UP; double _TOLERANCE_DOWN; int[] _OBJECT = new int[_JUMLAH + 1]; int _BANYAK; bool _CHECK = false; int _INDEKS; int _MODE; _MODE = 0; _INDEKS = 0; _TOLERANCE = 10; _BANYAK = 0; for (int c = 1; c <= _JUMLAH; c++) { foreach (int u in _OBJECT) { if (u == _OBJECT_ID[c]) { _CHECK = true; }
B - 17
} if (_CHECK == false) { _TOLERANCE_UP = (_OBJECT_SHAPE[c] + (_OBJECT_SHAPE[c] * (_TOLERANCE / 100))); _TOLERANCE_DOWN = (_OBJECT_SHAPE[c] (_OBJECT_SHAPE[c] * (_TOLERANCE / 100))); for (int i = c; i <= _JUMLAH; i++) { if ((_OBJECT_SHAPE[i] >= _TOLERANCE_DOWN) && (_OBJECT_SHAPE[i] <= _TOLERANCE_UP)) { foreach (int u in _OBJECT) { if (u == _OBJECT_ID[i]) { _CHECK = true; } if (u > 0) { _INDEKS++; } } if (_CHECK == false) { _OBJECT[_INDEKS] = _OBJECT_ID[i]; _BANYAK++; } } _INDEKS = 0; } _MODE++; if (_MODE == 1) { ImageProcessing Processing_1st = new ImageProcessing();
Processing_1st.setGAMBAR((Bitmap)(frm_MAIN.saya.pic_DISPLAY.Image));
B - 18
Processing_1st.ShowPartial(_OBJECT_X_START[c], _OBJECT_Y_START[c], _OBJECT_X_END[c], _OBJECT_Y_END[c]); pic_OBJECT_1st.Image = ((Bitmap)Processing_1st.GAMBAR); pic_OBJECT_1st.SizeMode = PictureBoxSizeMode.StretchImage; lbl_OBJECT_1st.Text = Convert.ToString(_BANYAK); } else if (_MODE == 2) { ImageProcessing Processing_2nd = new ImageProcessing();
Processing_2nd.setGAMBAR((Bitmap)(frm_MAIN.saya.pic_DISPLAY.Image)); Processing_2nd.ShowPartial(_OBJECT_X_START[c], _OBJECT_Y_START[c], _OBJECT_X_END[c], _OBJECT_Y_END[c]); pic_OBJECT_2nd.Image = ((Bitmap)Processing_2nd.GAMBAR); pic_OBJECT_2nd.SizeMode = PictureBoxSizeMode.StretchImage; lbl_OBJECT_2nd.Text = Convert.ToString(_BANYAK); } else if (_MODE == 3) { ImageProcessing Processing_3rd = new ImageProcessing();
Processing_3rd.setGAMBAR((Bitmap)(frm_MAIN.saya.pic_DISPLAY.Image)); Processing_3rd.ShowPartial(_OBJECT_X_START[c], _OBJECT_Y_START[c], _OBJECT_X_END[c], _OBJECT_Y_END[c]); pic_OBJECT_3rd.Image = ((Bitmap)Processing_3rd.GAMBAR); pic_OBJECT_3rd.SizeMode = PictureBoxSizeMode.StretchImage; lbl_OBJECT_3rd.Text = Convert.ToString(_BANYAK); } else if (_MODE == 4) { ImageProcessing Processing_4th = new ImageProcessing();
Processing_4th.setGAMBAR((Bitmap)(frm_MAIN.saya.pic_DISPLAY.Image)); Processing_4th.ShowPartial(_OBJECT_X_START[c], _OBJECT_Y_START[c], _OBJECT_X_END[c], _OBJECT_Y_END[c]);
B - 19
pic_OBJECT_4th.Image = ((Bitmap)Processing_4th.GAMBAR); pic_OBJECT_4th.SizeMode = PictureBoxSizeMode.StretchImage; lbl_OBJECT_4th.Text = Convert.ToString(_BANYAK); } _BANYAK = 0; } _CHECK = false; } } private void frm_CLASSIFICATION_Load(object sender, EventArgs e) { double _JUMLAH_KLAS; double _ERROR_KLAS; double _JUMLAH_OBJ1; double _JUMLAH_OBJ2; double _JUMLAH_OBJ3; double _JUMLAH_OBJ4; pic_DISPLAY.Image = (Bitmap)(frm_MAIN.saya.pic_DISPLAY.Image); pic_DISPLAY.SizeMode = PictureBoxSizeMode.StretchImage; Processor(); _JUMLAH_OBJ1 = Convert.ToDouble(lbl_OBJECT_1st.Text); _JUMLAH_OBJ2 = Convert.ToDouble(lbl_OBJECT_2nd.Text); _JUMLAH_OBJ3 = Convert.ToDouble(lbl_OBJECT_3rd.Text); _JUMLAH_OBJ4 = Convert.ToDouble(lbl_OBJECT_4th.Text); _JUMLAH_KLAS = _JUMLAH_OBJ1 + _JUMLAH_OBJ2 + _JUMLAH_OBJ3 + _JUMLAH_OBJ4; _ERROR_KLAS = (((_JUMLAH - _JUMLAH_KLAS) / _JUMLAH) * 100.0); lbl_JML_KLASIFIKASI.Text = Convert.ToString(_JUMLAH_KLAS); lbl_JML_ERROR.Text = Convert.ToString(_ERROR_KLAS) + " %"; lbl_JML_TOTAL.Text = Convert.ToString(_JUMLAH); }
B - 20
private void cmd_OK_Click(object sender, EventArgs e) { this.Close(); }
} } B.6 LISTING PROGRAM PADA FORM CLASS IMAGE PROCESSING using System; using System.Collections; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Text; namespace iCout_U____Does_it { public class ImageProcessing { private Bitmap _GAMBAR; public ImageProcessing() { } public Bitmap GAMBAR { get { return _GAMBAR; } } public void setGAMBAR(Bitmap IMAGE) { _GAMBAR = (Bitmap)IMAGE.Clone(); }
B - 21
public void ShowPartial(int _OBJECT_X_START, int _OBJECT_Y_START, int _OBJECT_X_END, int _OBJECT_Y_END) { RectangleF _KOTAK = new RectangleF(_OBJECT_X_START,_OBJECT_Y_START,(_OBJECT_X_END _OBJECT_X_START),(_OBJECT_Y_END - _OBJECT_Y_START)); Bitmap _TempGAMBAR = GAMBAR.Clone(_KOTAK,GAMBAR.PixelFormat); _GAMBAR = (Bitmap)_TempGAMBAR.Clone(); } public void ConvertToGrayScale() { Bitmap _TempGAMBAR = new Bitmap(_GAMBAR.Width, _GAMBAR.Height, PixelFormat.Format32bppArgb); BitmapData _dGAMBAR = _GAMBAR.LockBits(new Rectangle(0, 0, _GAMBAR.Width, _GAMBAR.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); BitmapData _dTempGAMBAR = _TempGAMBAR.LockBits(new Rectangle(0, 0, _TempGAMBAR.Width, _TempGAMBAR.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); unsafe { byte* _pGAMBAR = (byte*)_dGAMBAR.Scan0; byte* _pTempGAMBAR = (byte*)_dTempGAMBAR.Scan0; for (int y = 0; y < _dGAMBAR.Height; y++) { for (int x = 0; x < _dGAMBAR.Width; x++) { _pTempGAMBAR[0] = (byte)((_pGAMBAR[2] * .3) + (_pGAMBAR[1] * .59) + (_pGAMBAR[0] * .11)); // B _pTempGAMBAR[1] = (byte)((_pGAMBAR[2] * .3) + (_pGAMBAR[1] * .59) + (_pGAMBAR[0] * .11)); // G _pTempGAMBAR[2] = (byte)((_pGAMBAR[2] * .3) + (_pGAMBAR[1] * .59) + (_pGAMBAR[0] * .11)); // R _pTempGAMBAR[3] = _pGAMBAR[3];
B - 22
_pGAMBAR += 4; _pTempGAMBAR += 4; } _pGAMBAR += _dGAMBAR.Stride - (_dGAMBAR.Width * 4); _pTempGAMBAR += _dTempGAMBAR.Stride (_dTempGAMBAR.Width * 4); } } _TempGAMBAR.UnlockBits(_dTempGAMBAR); _GAMBAR.UnlockBits(_dGAMBAR); _GAMBAR = (Bitmap)_TempGAMBAR.Clone(); } public void ConvertToBinaryManual(int _TRESHOLD) { Bitmap _TempGAMBAR = new Bitmap(_GAMBAR.Width, _GAMBAR.Height, PixelFormat.Format32bppArgb); BitmapData _dGAMBAR = _GAMBAR.LockBits(new Rectangle(0, 0, _GAMBAR.Width, _GAMBAR.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); BitmapData _dTempGAMBAR = _TempGAMBAR.LockBits(new Rectangle(0, 0, _TempGAMBAR.Width, _TempGAMBAR.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); int _BIN = 0; unsafe { byte* _pGAMBAR = (byte*)_dGAMBAR.Scan0; byte* _pTempGAMBAR = (byte*)_dTempGAMBAR.Scan0; for (int y = 0; y < _dGAMBAR.Height; y++) { for (int x = 0; x < _dGAMBAR.Width; x++) { _BIN = (int)((_pGAMBAR[2] * .3) + (_pGAMBAR[1] * .59) + (_pGAMBAR[0] * .11));
B - 23
_BIN = (_BIN <= _TRESHOLD ? _BIN = 0 : 255); _pTempGAMBAR[0] = (byte)_BIN; _pTempGAMBAR[1] = (byte)_BIN; _pTempGAMBAR[2] = (byte)_BIN; _pTempGAMBAR[3] = _pGAMBAR[3]; _pGAMBAR += 4; _pTempGAMBAR += 4; } _pGAMBAR += _dGAMBAR.Stride - (_dGAMBAR.Width * 4); _pTempGAMBAR += _dTempGAMBAR.Stride (_dTempGAMBAR.Width * 4); } } _TempGAMBAR.UnlockBits(_dTempGAMBAR); _GAMBAR.UnlockBits(_dGAMBAR); _GAMBAR = (Bitmap)_TempGAMBAR.Clone(); } public void ConvertToBinaryAutomatic() { int[,] _PIXEL = new int[_GAMBAR.Width, _GAMBAR.Height]; int[] _HISTOGRAM = new int[256]; int _THRESHOLD; int _INDEX; _THRESHOLD = 0; _INDEX = 0; ConvertToGrayScale(); _PIXEL = Pixel("R"); _HISTOGRAM = Histogram("R"); Bitmap _TempGAMBAR = new Bitmap(_GAMBAR.Width, _GAMBAR.Height, PixelFormat.Format32bppArgb); BitmapData _dGAMBAR = _GAMBAR.LockBits(new Rectangle(0, 0, _GAMBAR.Width, _GAMBAR.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
B - 24
BitmapData _dTempGAMBAR = _TempGAMBAR.LockBits(new Rectangle(0, 0, _TempGAMBAR.Width, _TempGAMBAR.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); unsafe { byte* _pGAMBAR = (byte*)_dGAMBAR.Scan0; byte* _pTempGAMBAR = (byte*)_dTempGAMBAR.Scan0; for (int o = 0; o < 256; o++) { if (_INDEX <= _HISTOGRAM[o]) { _INDEX = _HISTOGRAM[o]; _THRESHOLD = o; } } _pGAMBAR = (byte*)_dGAMBAR.Scan0; for (int y = 0; y < _dGAMBAR.Height; y++) { for (int x = 0; x < _dGAMBAR.Width; x++) { _PIXEL[x, y] = (_PIXEL[x, y] == _THRESHOLD ? 0 : 255); _pTempGAMBAR[0] = (byte)_PIXEL[x, y]; _pTempGAMBAR[1] = (byte)_PIXEL[x, y]; _pTempGAMBAR[2] = (byte)_PIXEL[x, y]; _pTempGAMBAR[3] = _pGAMBAR[3];
_pGAMBAR += 4; _pTempGAMBAR += 4; } _pGAMBAR += _dGAMBAR.Stride - (_dGAMBAR.Width * 4); _pTempGAMBAR += _dTempGAMBAR.Stride (_dTempGAMBAR.Width * 4); } } _TempGAMBAR.UnlockBits(_dTempGAMBAR);
B - 25
_GAMBAR.UnlockBits(_dGAMBAR); _GAMBAR = (Bitmap)_TempGAMBAR.Clone(); } public int [] Histogram(string _MODE) { BitmapData _dGAMBAR = _GAMBAR.LockBits(new Rectangle(0, 0, _GAMBAR.Width, _GAMBAR.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); int[,] _PIXEL = new int[_GAMBAR.Width, _GAMBAR.Height]; int[] _HISTOGRAM = new int[256]; unsafe { byte* _pGAMBAR = (byte*)_dGAMBAR.Scan0; for (int y = 0; y < _dGAMBAR.Height; y++) { for (int x = 0; x < _dGAMBAR.Width; x++) { if (_MODE == "R") { _PIXEL[x, y] = (byte)_pGAMBAR[2]; } else if (_MODE == "G") { _PIXEL[x, y] = (byte)_pGAMBAR[1]; } else if (_MODE == "B") { _PIXEL[x, y] = (byte)_pGAMBAR[0]; } _HISTOGRAM[_PIXEL[x, y]]++; _pGAMBAR += 4; } _pGAMBAR += _dGAMBAR.Stride - (_dGAMBAR.Width * 4); }
B - 26
} _GAMBAR.UnlockBits(_dGAMBAR); return _HISTOGRAM; } public int[,] Pixel(string _MODE) { BitmapData _dGAMBAR = _GAMBAR.LockBits(new Rectangle(0, 0, _GAMBAR.Width, _GAMBAR.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); int[,] _PIXEL = new int[_GAMBAR.Width, _GAMBAR.Height]; unsafe { byte* _pGAMBAR = (byte*)_dGAMBAR.Scan0; for (int y = 0; y < _dGAMBAR.Height; y++) { for (int x = 0; x < _dGAMBAR.Width; x++) { if (_MODE == "R") { _PIXEL[x, y] = (byte)_pGAMBAR[2]; } else if (_MODE == "G") { _PIXEL[x, y] = (byte)_pGAMBAR[1]; } else if (_MODE == "B") { _PIXEL[x, y] = (byte)_pGAMBAR[0]; } _pGAMBAR += 4; } _pGAMBAR += _dGAMBAR.Stride - (_dGAMBAR.Width * 4); } } _GAMBAR.UnlockBits(_dGAMBAR); return _PIXEL;
B - 27
} } }
B.6 LISTING PROGRAM PADA FORM CLASS COMPUTER VISION using System; using System.Collections; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Text;
namespace iCout_U____Does_it { public class ComputerVision { private Bitmap _GAMBAR; public ComputerVision() { } public Bitmap GAMBAR { get { return _GAMBAR; } } public void setGAMBAR(Bitmap IMAGE) { _GAMBAR = (Bitmap)IMAGE.Clone(); }
B - 28
public string RGBStreamText(string _PATH) { ImageProcessing Processing = new ImageProcessing(); StreamWriter Text = new StreamWriter(_PATH); string _R; string _G; string _B; int int int
[,] _RE = new int[_GAMBAR.Width, _GAMBAR.Height]; [,] _BL = new int[_GAMBAR.Width, _GAMBAR.Height]; [,] _GR = new int[_GAMBAR.Width, _GAMBAR.Height];
Processing.setGAMBAR(_GAMBAR); _RE = Processing.Pixel("R"); _BL = Processing.Pixel("B"); _GR = Processing.Pixel("G"); for (int y = 0; y < _GAMBAR.Height; y++) { for (int x = 0; x < _GAMBAR.Width; x++) { _R = Convert.ToString(_RE[x, y]); _G = Convert.ToString(_GR[x, y]); _B = Convert.ToString(_BL[x, y]); if (_R.Length == 1) { _R = "00" + _R; } else if (_R.Length == 2) { _R = "0" + _R; } if (_G.Length == 1) { _G = "00" + _G; } else if (_G.Length == 2) { _G = "0" + _G; } if (_B.Length == 1) { _B = "00" + _B; } else if (_B.Length == 2) { _B = "0" + _B; } Text.Write(_R + ":" + _G + ":" + _B + "\t"); } Text.WriteLine(""); } Text.Close(); return _PATH; }
B - 29
public string BINStreamText(string _PATH) { ImageProcessing Processing = new ImageProcessing(); StreamWriter Text = new StreamWriter(_PATH); string _R; int[,] _RE = new int[_GAMBAR.Width, _GAMBAR.Height]; Processing.setGAMBAR(_GAMBAR); _RE = Processing.Pixel("R"); for (int y = 0; y < _GAMBAR.Height; y++) { for (int x = 0; x < _GAMBAR.Width; x++) { _R = Convert.ToString(_RE[x, y]); _R = (_R == "255" ? "1" : "0"); Text.Write(_R + " "); } Text.WriteLine(""); } Text.Close(); return _PATH; } public string LABStreamText(string _PATH) { ImageProcessing Processing = new ImageProcessing(); XMLProcessor XML = new XMLProcessor(); StreamWriter Text = new StreamWriter(_PATH); int _COUNTER = 1; int _JUMLAH = 0; int _INDEKS; int _ID = 0; int _CEKBORDER = 0; int[,] _PIXEL = new int[_GAMBAR.Width, _GAMBAR.Height];
B - 30
int[] _OBJECT_ID = new int[_GAMBAR.Width + _GAMBAR.Height]; int[] _OBJECT_X_START = new int[_GAMBAR.Width + _GAMBAR.Height]; int[] _OBJECT_X_END = new int[_GAMBAR.Width + _GAMBAR.Height]; int[] _OBJECT_Y_START = new int[_GAMBAR.Width + _GAMBAR.Height]; int[] _OBJECT_Y_END = new int[_GAMBAR.Width + _GAMBAR.Height]; double[] _OBJECT_KELILING = new double[_GAMBAR.Width + _GAMBAR.Height]; double[] _OBJECT_LUAS = new double[_GAMBAR.Width + _GAMBAR.Height]; double[] _OBJECT_SHAPE = new double[_GAMBAR.Width + _GAMBAR.Height]; bool _CHECK = false; unsafe { Processing.setGAMBAR(_GAMBAR); _PIXEL = Processing.Pixel("R"); for (int y = 1; y < _GAMBAR.Height; y++) { for (int x = 1; x < _GAMBAR.Width; x++) { _PIXEL[x, y] = (_PIXEL[x, y] == 255 ? 1 : 0); } } for (int y = 1; y < _GAMBAR.Height; y++) { for (int x = 1; x < _GAMBAR.Width; x++) { if (_PIXEL[x, y] > 0) { if ( (((_PIXEL[x, (y - 1)] < 2) && (_PIXEL[x, (y + 1)] < 2)) && ((_PIXEL[(x - 1), y] < 2) && (_PIXEL[(x + 1), y] < 2))) && (((_PIXEL[(x + 1), (y - 1)] < 2) && (_PIXEL[(x + 1), (y + 1)] < 2)) && ((_PIXEL[(x - 1), (y - 1)] < 2) && (_PIXEL[(x - 1), (y + 1)] < 2))) ) { _COUNTER++;
B - 31
_PIXEL[x, y] = _COUNTER; _PIXEL[x, (y - 1)] = (_PIXEL[x, (y - 1)] == 1 ? _COUNTER : 0); _PIXEL[x, (y + 1)] = (_PIXEL[x, (y + 1)] == 1 ? _COUNTER : 0); _PIXEL[(x + 1), y] = (_PIXEL[(x + 1), y] == 1 ? _COUNTER : 0); _PIXEL[(x - 1), y] = (_PIXEL[(x - 1), y] == 1 ? _COUNTER : 0); _PIXEL[(x + 1), (y - 1)] = (_PIXEL[(x + 1), (y - 1)] == 1 ? _COUNTER : 0); _PIXEL[(x + 1), (y + 1)] = (_PIXEL[(x + 1), (y + 1)] == 1 ? _COUNTER : 0); _PIXEL[(x - 1), (y - 1)] = (_PIXEL[(x - 1), (y - 1)] == 1 ? _COUNTER : 0); _PIXEL[(x - 1), (y + 1)] = (_PIXEL[(x - 1), (y + 1)] == 1 ? _COUNTER : 0); } else { if ((_PIXEL[x, (y - 1)] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[x, (y - 1)] ? _PIXEL[x, y] : _PIXEL[x, (y - 1)]); } else if ((_PIXEL[x, (y - 1)] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[x, (y - 1)]; } if ((_PIXEL[x, (y + 1)] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[x, (y + 1)] ? _PIXEL[x, y] : _PIXEL[x, (y + 1)]); } else if ((_PIXEL[x, (y + 1)] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[x, (y + 1)]; } if ((_PIXEL[(x - 1), y] > 1) && (_PIXEL[x, y] > 1))
B - 32
{ _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[(x - 1), y] ? _PIXEL[x, y] : _PIXEL[(x - 1), y]); } else if ((_PIXEL[(x - 1), y] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[(x - 1), y]; } if ((_PIXEL[(x + 1), y] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[(x + 1), y] ? _PIXEL[x, y] : _PIXEL[(x + 1), y]); } else if ((_PIXEL[(x + 1), y] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[(x + 1), y]; } if ((_PIXEL[(x + 1), (y - 1)] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[(x + 1), (y - 1)] ? _PIXEL[x, y] : _PIXEL[(x + 1), (y - 1)]); } else if ((_PIXEL[(x + 1), (y - 1)] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[(x + 1), (y - 1)]; } if ((_PIXEL[(x + 1), (y + 1)] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[(x + 1), (y + 1)] ? _PIXEL[x, y] : _PIXEL[(x + 1), (y + 1)]); } else if ((_PIXEL[(x + 1), (y + 1)] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[(x + 1), (y + 1)]; } if ((_PIXEL[(x - 1), (y - 1)] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[(x - 1), (y - 1)] ? _PIXEL[x, y] : _PIXEL[(x - 1), (y - 1)]); }
B - 33
else if ((_PIXEL[(x - 1), (y - 1)] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[(x - 1), (y - 1)]; } if ((_PIXEL[(x - 1), (y + 1)] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[(x - 1), (y + 1)] ? _PIXEL[x, y] : _PIXEL[(x - 1), (y + 1)]); } else if ((_PIXEL[(x - 1), (y + 1)] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[(x - 1), (y + 1)]; } _PIXEL[x, (y - 1)] = (_PIXEL[x, (y - 1)] > 0 ? _PIXEL[x, y] : _PIXEL[x, (y - 1)]); _PIXEL[x, (y + 1)] = (_PIXEL[x, (y + 1)] > 0 ? _PIXEL[x, y] : _PIXEL[x, (y + 1)]); _PIXEL[(x + 1), y] = (_PIXEL[(x + 1), y] > 0 ? _PIXEL[x, y] : _PIXEL[(x + 1), y]); _PIXEL[(x - 1), y] = (_PIXEL[(x - 1), y] > 0 ? _PIXEL[x, y] : _PIXEL[(x - 1), y]); _PIXEL[(x + 1), (y - 1)] = (_PIXEL[(x + 1), (y - 1)] > 0 ? _PIXEL[x, y] : _PIXEL[(x + 1), (y - 1)]); _PIXEL[(x + 1), (y + 1)] = (_PIXEL[(x + 1), (y + 1)] > 0 ? _PIXEL[x, y] : _PIXEL[(x + 1), (y + 1)]); _PIXEL[(x - 1), (y - 1)] = (_PIXEL[(x - 1), (y - 1)] > 0 ? _PIXEL[x, y] : _PIXEL[(x - 1), (y - 1)]); _PIXEL[(x - 1), (y + 1)] = (_PIXEL[(x - 1), (y + 1)] > 0 ? _PIXEL[x, y] : _PIXEL[(x - 1), (y + 1)]); } } } } for (int y = (_GAMBAR.Height - 1); y >= 1; y--) { for (int x = (_GAMBAR.Width - 1); x >= 1; x--) { if (_PIXEL[x, y] > 0) { if ((_PIXEL[x, (y - 1)] > 1) && (_PIXEL[x, y] > 1))
B - 34
{ _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[x, (y - 1)] ? _PIXEL[x, y] : _PIXEL[x, (y - 1)]); } else if ((_PIXEL[x, (y - 1)] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[x, (y - 1)]; } if ((_PIXEL[x, (y + 1)] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[x, (y + 1)] ? _PIXEL[x, y] : _PIXEL[x, (y + 1)]); } else if ((_PIXEL[x, (y + 1)] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[x, (y + 1)]; } if ((_PIXEL[(x - 1), y] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[(x - 1), y] ? _PIXEL[x, y] : _PIXEL[(x - 1), y]); } else if ((_PIXEL[(x - 1), y] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[(x - 1), y]; } if ((_PIXEL[(x + 1), y] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[(x + 1), y] ? _PIXEL[x, y] : _PIXEL[(x + 1), y]); } else if ((_PIXEL[(x + 1), y] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[(x + 1), y]; } if ((_PIXEL[(x + 1), (y - 1)] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[(x + 1), (y - 1)] ? _PIXEL[x, y] : _PIXEL[(x + 1), (y - 1)]); }
B - 35
else if ((_PIXEL[(x + 1), (y - 1)] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[(x + 1), (y - 1)]; } if ((_PIXEL[(x + 1), (y + 1)] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[(x + 1), (y + 1)] ? _PIXEL[x, y] : _PIXEL[(x + 1), (y + 1)]); } else if ((_PIXEL[(x + 1), (y + 1)] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[(x + 1), (y + 1)]; } if ((_PIXEL[(x - 1), (y - 1)] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[(x - 1), (y - 1)] ? _PIXEL[x, y] : _PIXEL[(x - 1), (y - 1)]); } else if ((_PIXEL[(x - 1), (y - 1)] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[(x - 1), (y - 1)]; } if ((_PIXEL[(x - 1), (y + 1)] > 1) && (_PIXEL[x, y] > 1)) { _PIXEL[x, y] = (_PIXEL[x, y] <= _PIXEL[(x - 1), (y + 1)] ? _PIXEL[x, y] : _PIXEL[(x - 1), (y + 1)]); } else if ((_PIXEL[(x - 1), (y + 1)] > 1) && (_PIXEL[x, y] == 1)) { _PIXEL[x, y] = _PIXEL[(x - 1), (y + 1)]; } _PIXEL[x, (y - 1)] = (_PIXEL[x, (y - 1)] > 0 ? _PIXEL[x, y] : _PIXEL[x, (y - 1)]); _PIXEL[x, (y + 1)] = (_PIXEL[x, (y + 1)] > 0 ? _PIXEL[x, y] : _PIXEL[x, (y + 1)]); _PIXEL[(x + 1), y] = (_PIXEL[(x + 1), y] > 0 ? _PIXEL[x, y] : _PIXEL[(x + 1), y]); _PIXEL[(x - 1), y] = (_PIXEL[(x - 1), y] > 0 ? _PIXEL[x, y] : _PIXEL[(x - 1), y]);
B - 36
_PIXEL[(x + 1), (y - 1)] = (_PIXEL[(x + 1), (y - 1)] > 0 ? _PIXEL[x, y] : _PIXEL[(x + 1), (y - 1)]); _PIXEL[(x + 1), (y + 1)] = (_PIXEL[(x + 1), (y + 1)] > 0 ? _PIXEL[x, y] : _PIXEL[(x + 1), (y + 1)]); _PIXEL[(x - 1), (y - 1)] = (_PIXEL[(x - 1), (y - 1)] > 0 ? _PIXEL[x, y] : _PIXEL[(x - 1), (y - 1)]); _PIXEL[(x - 1), (y + 1)] = (_PIXEL[(x - 1), (y + 1)] > 0 ? _PIXEL[x, y] : _PIXEL[(x - 1), (y + 1)]); } } } for (int y = 1; y < _GAMBAR.Height; y++) { _INDEKS = 0; for (int x = 1; x < _GAMBAR.Width; x++) { if (_PIXEL[x, y] > 0) { _INDEKS = 0; _CHECK = false; for (int o = 1; o < (_GAMBAR.Height + _GAMBAR.Width); o++) { if (_OBJECT_ID[o] == _PIXEL[x, y]) { _CHECK = true; _ID = o; } } _INDEKS = (_CHECK == true ? _ID : 0); if (_INDEKS > 0) { _OBJECT_X_START[_INDEKS] = (_OBJECT_X_START[_INDEKS] > x ? x : _OBJECT_X_START[_INDEKS]); _OBJECT_Y_START[_INDEKS] = (_OBJECT_Y_START[_INDEKS] > y ? y : _OBJECT_Y_START[_INDEKS]); _OBJECT_X_END[_INDEKS] = (_OBJECT_X_END[_INDEKS] < x ? x : _OBJECT_X_END[_INDEKS]); _OBJECT_Y_END[_INDEKS] = (_OBJECT_Y_END[_INDEKS] < y ? y : _OBJECT_Y_END[_INDEKS]); _OBJECT_LUAS[_INDEKS]++;
B - 37
_CEKBORDER = 0; _CEKBORDER = (_PIXEL[x, (y + 1)] == 0 ? _CEKBORDER + 1 : _CEKBORDER); _CEKBORDER = (_PIXEL[x, (y - 1)] == 0 ? _CEKBORDER + 1 : _CEKBORDER); _CEKBORDER = (_PIXEL[(x + 1), y] == 0 ? _CEKBORDER + 1 : _CEKBORDER); _CEKBORDER = (_PIXEL[(x - 1), y] == 0 ? _CEKBORDER + 1 : _CEKBORDER); _OBJECT_KELILING[_INDEKS] = (_CEKBORDER > 0 ? _OBJECT_KELILING[_INDEKS] + 1 : _OBJECT_KELILING[_INDEKS]); _OBJECT_SHAPE[_INDEKS] = ((_OBJECT_KELILING[_INDEKS] * _OBJECT_KELILING[_INDEKS]) / _OBJECT_LUAS[_INDEKS]); } else { foreach (int a in _OBJECT_ID) { if (a > 0) { _INDEKS++; } } _INDEKS = (_INDEKS < 1 ? 1 : (_INDEKS + 1)); _OBJECT_ID[_INDEKS] = _PIXEL[x, y]; _OBJECT_X_START[_INDEKS] = x; _OBJECT_X_END[_INDEKS] = x; _OBJECT_Y_START[_INDEKS] = y; _OBJECT_Y_END[_INDEKS] = y; _OBJECT_LUAS[_INDEKS]++; _CEKBORDER = 0; _CEKBORDER = (_PIXEL[x, (y + 1)] == 0 ? _CEKBORDER + 1 : _CEKBORDER);
B - 38
_CEKBORDER = (_PIXEL[x, (y - 1)] == 0 ? _CEKBORDER + 1 : _CEKBORDER); _CEKBORDER = (_PIXEL[(x + 1), y] == 0 ? _CEKBORDER + 1 : _CEKBORDER); _CEKBORDER = (_PIXEL[(x - 1), y] == 0 ? _CEKBORDER + 1 : _CEKBORDER); _OBJECT_KELILING[_INDEKS] = (_CEKBORDER > 0 ? _OBJECT_KELILING[_INDEKS] + 1 : _OBJECT_KELILING[_INDEKS]); _OBJECT_SHAPE[_INDEKS] = ((_OBJECT_KELILING[_INDEKS] * _OBJECT_KELILING[_INDEKS]) / _OBJECT_LUAS[_INDEKS]); } } } } foreach (int a in _OBJECT_ID) { if (a > 0) { _JUMLAH++; } } for (int y = 0; y < _GAMBAR.Height; y++) { for (int x = 0; x < _GAMBAR.Width; x++) { Text.Write(_PIXEL[x, y] + " "); } Text.WriteLine(""); } Text.Close(); XML.setPATH(_PATH); XML.setJUMLAH(_JUMLAH); XML.setOBJECT_ID(_OBJECT_ID); XML.setOBJECT_X_START(_OBJECT_X_START); XML.setOBJECT_Y_START(_OBJECT_Y_START); XML.setOBJECT_X_END(_OBJECT_X_END);
B - 39
XML.setOBJECT_Y_END(_OBJECT_Y_END); XML.setOBJECT_KELILING(_OBJECT_KELILING); XML.setOBJECT_LUAS(_OBJECT_LUAS); XML.setOBJECT_SHAPE(_OBJECT_SHAPE); XML.CreateXML(); frm_MAIN.saya.setJUMLAH(_JUMLAH); frm_MAIN.saya.setOBJECT_ID(_OBJECT_ID); frm_MAIN.saya.setOBJECT_X_START(_OBJECT_X_START); frm_MAIN.saya.setOBJECT_Y_START(_OBJECT_Y_START); frm_MAIN.saya.setOBJECT_X_END(_OBJECT_X_END); frm_MAIN.saya.setOBJECT_Y_END(_OBJECT_Y_END); frm_MAIN.saya.setOBJECT_KELILING(_OBJECT_KELILING); frm_MAIN.saya.setOBJECT_LUAS(_OBJECT_LUAS); frm_MAIN.saya.setOBJECT_SHAPE(_OBJECT_SHAPE); return _PATH; } } } } B.7 LISTING PROGRAM PADA FORM CLASS PROGRAM using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace iCout_U____Does_it { static class cls_PROGRAM { /// <summary> /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frm_SPLASH());
B - 40
} } } B.8 LISTING PROGRAM PADA FORM CLASS XMLPROCESSOR using System; using System.Collections; using System.Data; using System.Xml; using System.Linq; using System.Text; using System.IO; namespace iCout_U____Does_it { public class XMLProcessor { private string _PATH; private int _JUMLAH; private int[] _OBJECT_ID; private int[] _OBJECT_X_START; private int[] _OBJECT_X_END; private int[] _OBJECT_Y_START; private int[] _OBJECT_Y_END; private double[] _OBJECT_KELILING; private double[] _OBJECT_LUAS; private double[] _OBJECT_SHAPE; public XMLProcessor() { } public void setPATH(string _PATHx) { _PATH = _PATHx; } public void setOBJECT_ID(params int[] _OBJECT_IDx) { _OBJECT_ID = _OBJECT_IDx; }
B - 41
public void setOBJECT_X_START(params int[] _OBJECT_X_STARTx) { _OBJECT_X_START = _OBJECT_X_STARTx; } public void setOBJECT_Y_START(params int[] _OBJECT_Y_STARTx) { _OBJECT_Y_START = _OBJECT_Y_STARTx; } public void setOBJECT_X_END(params int[] _OBJECT_X_ENDx) { _OBJECT_X_END = _OBJECT_X_ENDx; } public void setOBJECT_Y_END(params int[] _OBJECT_Y_ENDx) { _OBJECT_Y_END = _OBJECT_Y_ENDx; } public void setOBJECT_KELILING(params double[] _OBJECT_KELILINGx) { _OBJECT_KELILING = _OBJECT_KELILINGx; } public void setOBJECT_LUAS(params double[] _OBJECT_LUASx) { _OBJECT_LUAS = _OBJECT_LUASx; } public void setOBJECT_SHAPE(params double[] _OBJECT_SHAPEx) { _OBJECT_SHAPE = _OBJECT_SHAPEx; } public void setJUMLAH(int _JUMLAHx) { _JUMLAH = _JUMLAHx; } public void CreateXML() { string _PATHx;
B - 42
_PATHx = Path.GetDirectoryName(_PATH) + "\\" + Path.GetFileNameWithoutExtension(_PATH) + ".icup"; XmlTextWriter myXmlTextWriter = new XmlTextWriter(_PATHx, System.Text.Encoding.UTF8); myXmlTextWriter.Formatting = Formatting.Indented; myXmlTextWriter.WriteStartDocument(false); myXmlTextWriter.WriteComment("ICout U! - Project File"); myXmlTextWriter.WriteStartElement("icup"); myXmlTextWriter.WriteStartElement("configuration", null); myXmlTextWriter.WriteElementString("pic_author", null, "Author Gambar"); myXmlTextWriter.WriteElementString("pic_name", null, "Nama Gambar"); myXmlTextWriter.WriteElementString("pic_crc", null, "CRC Gambar"); myXmlTextWriter.WriteElementString("pic_format", null, "Format Gambar"); myXmlTextWriter.WriteEndElement(); myXmlTextWriter.Flush();
myXmlTextWriter.WriteStartElement("information", null); for (int v = 1; v <= _JUMLAH; v++) { myXmlTextWriter.WriteStartElement("object", null); myXmlTextWriter.WriteElementString("object-id", null, Convert.ToString(_OBJECT_ID[v])); myXmlTextWriter.WriteElementString("object-start-x", null, Convert.ToString(_OBJECT_X_START[v])); myXmlTextWriter.WriteElementString("object-start-y", null, Convert.ToString(_OBJECT_Y_START[v])); myXmlTextWriter.WriteElementString("object-end-x", null, Convert.ToString(_OBJECT_X_END[v])); myXmlTextWriter.WriteElementString("object-end-y", null, Convert.ToString(_OBJECT_Y_END[v]));
B - 43
myXmlTextWriter.WriteElementString("object-luas", null, Convert.ToString(_OBJECT_LUAS[v])); myXmlTextWriter.WriteElementString("object-keliling", null, Convert.ToString(_OBJECT_KELILING[v])); myXmlTextWriter.WriteElementString("object-shapefactor", null, Convert.ToString(_OBJECT_SHAPE[v])); myXmlTextWriter.WriteEndElement(); } myXmlTextWriter.WriteEndElement(); myXmlTextWriter.WriteEndElement(); myXmlTextWriter.Flush(); myXmlTextWriter.Close(); } } }
B - 44
LAMPIRAN C PENGENALAN VISUAL C#
PENGENALAN VISUAL C# Microsoft Visual C#.NET adalah sebuah bahasa pemrograman baru dalam dunia teknologi informasi, dengan berbasiskan platform baru yang di kembangkan oleh Microsoft sebagai salah satu produsen perangkat lunak yang cukup dominan yakni platform .NET Framework, kelebihan dari digunakannya platform baru ini tidak lain adalah .NET Framework menawarkan kompabitilas dan portabilitas yang sangat signifingkan jika di bandingkan dengan bahasa penprograman lain di luar .NET Framework. Dengan teknologi .NET Framework sangatlah memungkinkan untuk mendesain sebuah perangkat lunak yang dapat berjalan di berbagai sistem operasi, prosesor, maupun berbagai peralatan elektronik yang mendukung platform .NET seperti PDA, SMART Phone dan peralatan elektronik lainnya. Kompabilitas yang sangat luas tersebut di mungkinkan tanpa melakukan compile ulang terhadap perangkat lunak yang telah dibuat, hal tersebut di mungkinkan karena teknologi .NET Framework mengadopsi teknologi virtualisasi CPU, sehingga perangkat lunak yang telah di kompilasi adalah perangkat lunak yang berjalan di atas framework virtual sehingga nantinya perangkat lunak tersebut tidak bergantung pada sistem operasi maupun jenis prosesor yang di gunakan.
C-1
C. 1
Integrated Development Environment ( IDE )
Gambar C.1 IDE Visual Studio 2008 Dalam melakukan pemrograman Visual C# tidak di perlukan suatu editor khusus, cukup dengan aplikasi teks editor seperti notepad, programmer dapat membuatu suatu perangkat lunak yang berbasiskan Visual C#, tetapi untuk membangun suatu perangkat yang memiliki tingkat kompleksitas yang tinggi maka diperlukan suatu “alat” untuk membantu dalam melakukan perancangan perangkat lunak mulai dari perancangan antar muka sampai penulisan kode program, oleh karena itu digunakan suatu IDE (Integrated Development Environment) sebagai alat bantu dalam membangun suatu perangkat lunak. Pada Gambar C.1 dapat dilihat bahwa IDE dari Visual Studio 2008 memiliki beberapa bagian, berikut adalah bagian – bagian dari IDE (Integrated Development Environment) tersebut beserta dengan penjelasannya :
C-2
Menu Bar, merupakan tempat menampilkan menu Visual Studio seperti File, Edit, View, Project, Build, Debug, Data, Format, Tools, Text, Window, Help. Jendela Toolbox, jendela ini berisi komponen - komponen atau objek-objek visual untuk melakukan pemrograman. Jendela Form Designer, merupakan tempat untuk merancang antarmuka perangkat lunak, objek – objek dari jendela Toolbox akan di tempatkan di jendela ini. Jendela Properties, adalah jendela berisikan karakteristik dari form dan objek-objek yang ada dalam form tersebut seperti ukuran, posisi, nama tampilan dan lain - lain. Jendela Error List, adalah jendela yang berfungsi untuk menunjukan kesalahan – kesalahan yang terjadi ketika kompilasi perangkat lunak di lakukan. Jendela Solution Explorer, pada jendela ini semua komponen – komponen dari perangkat lunak yang digunakan dalam percangan dapat dilihat.
C. 2
Jenis – jenis Kontrol pada Visual C#
Gambar C.2 Kontrol pada kategori Commond Controls
C-3
Gambar C.2 Menunjukan kontrol – kontrol yang sering digunakan dalam membangun suatu perangkat lunak, untuk lebih jelas mengenai fungsi dan deskripsi dari kontrol – kontrol diatas dapat dilihat pada tabel C.1. Tabel C.1 Fungsi dan deskripsi dari kontrol – kontrol dalam kategori Command Controls. Nama Kontrol
MonthCalendar NotifyIcon NumericUpDown PictureBox
Keterangan Digunakan untuk membangkitkan event proses tertentu ketika pemakai melakukan operasi klik terhadap kontrol ini. Digunakan untuk melakukan satu atau lebih pilihan bernilai yes/no, true/false. Merupakan gabungan dari ListBox dan CheckBox, dan memiliki fungsi sama seperti CheckBox. Digunakan untuk menampung suatu item data dengan style dropdown. Digunakan untuk mengambil data yang berupa waktu, untuk selanjutnya di lakukan proses. Digunakan untuk menampilkan teks yang tidak dapat diubah oleh pemakai. Digunakan untuk menampilkan teks yang tidak dapat diubah oleh pemakai, tidak seperti label biasa label jenis ini dapat diisi dengan link. Digunakan untuk menampung suatu item data dengan style datalist. Digunakan untuk menampung komponen - komponen dalam suatu perangkat lunak. Digunakan untuk menampung suatu teks yang memiliki ukuran terbatas, tetapi menampilkan text dengan format yang telah di tentukan. Digunakan untuk mengambil data yang hanya bernilai bulan dari suatu waktu. Digunakan untuk membuat suatu icon yang akan bereaksi jika suatu event terpenuhi. Digunakan untuk mengambil nilai numerik. Digunakan untuk menampilkan suatu gambar yang akan di proses atau telah diproses.
Pointer
Mengembalikan mouse pointer jika telah selesai melakukan penambahan kontrol ke form.
ProgressBar RadioButton RichTextBox TextBox
TreeView
Digunakan untuk mengetahui seberapa persentase kemajuan suatu proses yang sedang di lakukan. Digunakan untuk melakukan hanya satu pilihan dan bernilai true/false. Digunakan untuk menampung suatu teks yang cukup besar. Digunakan untuk menampung teks yang memiliki ukuran terbatas. Digunakan untuk memberikan informasi kepada pengguna perangkat lunak mengenai kontrol yang ada pada perangkat lunak tersebut. Digunakan untuk menampilkan data - data dengan bentuk pohon.
WebBrowser
Digunakan untuk menampilkan situs dari suatu situs di internet.
Button CheckBox CheckedListBox ComboBox DateTimePicker Label LinkLabel ListBox ListView MaskedTextBox
ToolTip
Selain menggunakan kontrol – kontrol yang ada pada kategori Common Controls, dalam melakukan perancangan suatu perangkat lunak dibutuhkan juga kontrol – kontrol yang berfungsi sebagai alat interaksi antara perangkat lunak dengan pengguna perangkat lunak itu sendiri. Kontrol – kontrol yang memiliki fungsi seperti yang telah disebutkan terdapat pada kontrol dengan kategori Dialogs ( Gambar C.3 ), untuk keterangan lebih lanjut mengenai kontrol – kontrol tersebut dapat dilihat pada tabel C.2.
C-4
Gambar C.3 Kontrol pada kategori Dialogs Tabel C.2 Fungsi dan deskripsi dari kontrol – kontrol dalam kategori Dialogs. Nama Kontrol Pointer ColorDialog FolderBrowser Dialog FontDialog
OpenFileDialog
SaveFileDialog
C. 3
Keterangan Mengembalikan mouse pointer jika telah selesai melakukan penambahan kontrol ke form. Kontrol dialog yang akan memunculkan suatu dialog yang meminta pemakai untuk memilih suatu warna. Kontrol dialog yang akan memunculkan suatu dialog yang meminta pemakai untuk memilih suatu folder. Kontrol dialog yang akan memunculkan suatu dialog yang meminta pemakai untuk memilih suatu jenis huruf beserta atributnya. Kontrol dialog yang akan memunculkan suatu dialog yang meminta pemakai untuk memilih suatu alamat di mana suatu file akan dibuka. Kontrol dialog yang akan memunculkan suatu dialog yang meminta pemakai untuk memilih suatu alamat di mana suatu file akan disimpan.
Dasar Pemrograman Visual C#
C. 3. 1 Variabel Sebagai bahasa pemrograman yang mengadopsi gaya penulisan C\C++ maka C# juga memiliki “perilaku” yang tidak berbeda jauh dengan C\C++, salah satu contoh nyata dari “perilaku” ini adalah bagaimana C# memperlakukan variabel – variabel yang akan di tulis dengan bahasa pemrograman ini bersifat strongly-typed yang berarti setiap variabel yang ada pada C# haruslah memiliki suatu tipe data tertentu dan variabel yang terlah di deklarasikan sebagai variabel yang memiliki suatu tipe data tersebut tidak dapat menangani tipe data lainnya, selain itu variabel dalam
C-5
C# juga bersifat case sensitive yang berarti C# membedakan penggunaan huruf kapital dan huruf kecil. Berikut ini adalah aturan – aturan penamaan variabel dalam C# : 1. Nama variabel hanya diijinkan terdiri dari huruf, angka dan karakter underscore ( _ ). 2. Variabel bersifat case sensitive. 3. Keyword tidak dapat digunakan sebagai nama variabel, terkecuali pada awal keyword tersebut di tambahkan karakter @ ( untuk daftar keyword dapat dilihat pada tabel C.3 )
Tabel C.3 Keyword pada C# abstract as base bool break byte case catch char checked class const continue decimal default delegate do double else enum
event explicit extern finally fixed float for foreach goto if implicit in int interface internal is lock long namespace new
null object operator out override params private protected public readonly ref return sbyte sealed short sizeof stackalloc static string struct
switch this throw try typeof uint ulong unchecked unsafe ushort using virtual void volatile while FALSE TRUE
Selain harus memperhatikan aturan – aturan dalam penamaan sebuah variabel, variabel juga harus memiliki suatu tipe yang nantinya akan mendeskripsikan nilai – nilai yang akan ditangani, untuk memperjelas mengenai tipe data yang ada dalam C#
C-6
maka dapat dilihat pada tabel C.4. Pada tabel dilihat bahwa penentuan tipe data pada suatu variabel dapat memberikan dampak yang cukup signifigkan dalam pembuatan perangkat lunak, hal ini dapat dilihat bahwa beberapa tipe data menggunakan relatif cukup banyak memory dalam penanganannya, bila semua variabel dalam perangkat lunak yang akan di buat menggunakan tipe yang menggunakan memory yang relatif boros tentunya mengakibatkan perangkat lunak tesebut akan berjalan kurang optimal.
Tabel C.4 Tipe Data pada C# Tipe bool byte char char decimal double float int
Ukuran ( Dalam Bit ) 8 16 128 64 32 32
long sbyte short string uint ulong
64 8 16 32 64
ushort
16
Range 0 sampai 255 0 sampai 65535 1.0 x 10-28 sampai 7.9 x 1028 5.0 x 10-324 sampai 1.7 x 10308 1.5 x 10-45 sampai 3.4 x 1038 -2147483648 sampai 2147483647 -9223372036854775808 sampai 9223372036854775807 -128 sampai 127 -32768 sampai 32767 0 sampai 4294967295 0 sampai 18446744073709551615 0
sampai 65535
C. 3. 2 Flow Control Hal yang tidak kalah pentingnya dalam pembuatan suatu perangkat lunak adalah flow control, dengan menggunakan sintaks – sintaks flow control event – event pada perangkat lunak yang dibangun dapat dengan mudah di kendalikan. Flow control pada C# memiliki sintaksis bahasa yang sama dengan bahasa pemrograman C\C++, kesamaan tersebut tidak hanya pada sintaksis melainkan juga pada penggunaan flow control tersebut.
C-7
Berikut ini adalah beberapa sintaks dari flow control beserta contoh penggunaannya dalam kode program : 1. if if statement digunakan untuk meneksekusi kode program jika kondisi tertentu terpenuhi. 2. if - else Merupakan variasi dari statement if, selain menetukan langkah apa yang harus dilakukan jika suatu kondisi terpenuhi, juga dapat menetukan langkah apa yang dilakukan apabila kondisi tersebut tidak terpenuhi. 3. switch switch merupakan variasi dari statement if - else. Statement ini biasa digunakan untuk mengecek beberapa kemungkinan dari suatu variabel. Berbeda dengan C yang pada statement switch hanya bisa menggunakan variabel numerik, C# dapat menggunakan string. 4. while while statement berguna untuk melakukan perulangan selama kondisi bernilai true. Pengecekan kondisi dilakukan di awal, sehingga memungkinkan proses loop tidak dijalankan sama sekali. 5. do - while do - while merupakan variasi dari statement while. Bedanya pengecekan variabel dilakukan di akhir. Ini berarti bahwa badan loop akan dijalankan minimal sekali. 6. for Seperti keluarga bahasa C lainnya, for digunakan untuk melakukan perulangan selama kondisi terpenuhi. Bedanya dengan while terdapat pada deklarasi statement for dapat menetukan 3 hal, kondisi awal, kondisi akhir perulangan ( kondisi pengecekan ) dan kondisi yang dilakukan tiap pada akhir perulangan.
C-8
7. foreach Bentuk iterasi khusus yang tidak berada di C adalah foreach, bentuk ini sebenarnya diambil dari Visual Basic (for each). Statement foreach digunakan untuk menelusuri suatu Collection, misalnya array.
C. 3. 3 Method Method adalah bagian dari tubuh program yang mengimplementasikan suatu action sehingga class atau object dapat bekerja. Beberapa method tersebut yakni : 1. Static Method Method dapat di overload, artinya satu nama method dapat dipakai berkalikali selama dia memiliki sesuatu yang unik. Sesuatu yang unik pada method tersebut dapat terdiri dari banyaknya parameter, type parameter atau modifier parameter yang berbeda. 2. Non - Static Method Static method dapat diakses hanya melalui class, sedangkan non-static method hanya dapat diakses melalui instance.
C. 3. 4 Modifier Modifier adalah keyword yang dipakai untuk menspesifikasikan deklarasi pengaksesan (akses level) suatu member atau type. Modifier yang harus diperhatikan dapat dilihat pada tabel C.5. Tabel C.5 Jenis – jenis Modifier Akes level Internal Private Protected Public
Keterangan Akses dibatasi hanya pada project yang sama Akses dibatasi hanya pada type / class nya Akses dibatasi pada classnya saja atau type yang diturunkan dari class Akses tidak dibatasi
Untuk mengenal lebih lanjut tentang bahasa pemrograman C# ini sebaiknya membaca beberapa referensi yang membahas secara khusus bahasa pemrograman ini.
C-9