Tugas cam

 

Nama: Muhammad Arkan Karindra Darvesh

NRP: 5025211236

Kelas: PBKK  B

Deskripsi Tugas:

Aforge .Net = sebuah library atau Framework open source yang dibuat untuk kebutuhan pemrosesan gambar pada C#.
Dibuat oleg Andrew Kirillov (desember 2006), 17 juli 2013 versi terakhir. 
Library aforge dimasukan ke dalam Framework accord dotnet
www.aforgenet.com/framework/features

Toolbox, form1
‌ComboBox :
WebcamList
‌Button : 4
Text1 - start
Name1, 2, 3,4- btnStart , btnCapt , btnSaveImg , btnExit
‌TableLayoutPanel :
Hapus satu baris
‌picturebox: 
Zoom, dockin parent controller
‌aforge
Folder Release (3 library) 
Dependenct -> project reference - (3 library) .dll, .video.directshow, .vidio






Dan hasil di save ke file dengan format png, kalian bisa memberi nama bebas pada file nya.

hasil save image button:



Source code :

<div style="background-color: blue; color: white; padding: 10px;">

   using AForge.Video;

using AForge.Video.DirectShow;

using System.Drawing;

using System.Drawing.Imaging;


namespace WebCamApp

{

    public partial class Form1 : Form

    {

        private FilterInfoCollection captureDevice;

        private VideoCaptureDevice captureDeviceVideo;

        public Form1()

        {

            InitializeComponent();

        }


        private void Form1_Load(object sender, EventArgs e)

        {

            captureDevice = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            foreach (FilterInfo deviceList in captureDevice)

            {

                comboBoxWebcam.Items.Add(deviceList.Name);

            }

            comboBoxWebcam.SelectedIndex = 0;

            captureDeviceVideo = new VideoCaptureDevice();

        }


        private void btnStart_Click(object sender, EventArgs e)

        {

            if (captureDeviceVideo.IsRunning)

            {

                captureDeviceVideo.SignalToStop();

                captureDeviceVideo.WaitForStop();

                pictureBox1.Image = null;

                pictureBox1.Invalidate();

            }

            captureDeviceVideo = new VideoCaptureDevice(captureDevice[comboBoxWebcam.SelectedIndex].MonikerString);

            captureDeviceVideo.NewFrame += new NewFrameEventHandler(CaptureDeviceVideo_NewFrame);

            captureDeviceVideo.Start();

        }


        private void CaptureDeviceVideo_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)

        {

            pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();

        }


        private void btnCapture_Click(object sender, EventArgs e)

        {

            pictureBox2.Image = (Bitmap)pictureBox1.Image.Clone();

        }


        private void btnSaveImg_Click(object sender, EventArgs e)

        {

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Title = "Save Image As";

            saveFileDialog.Filter = "Image Files (*.jpg, *.png) | *.jpg, *.png";

            ImageFormat imageFormat = ImageFormat.Png;


            if(saveFileDialog.ShowDialog() == DialogResult.OK)

            {

                string ext = System.IO.Path.GetExtension(saveFileDialog.FileName);

                switch (ext)

                {

                    case ".jpg":

                        imageFormat = ImageFormat.Jpeg; break;

                    case ".png":

                        imageFormat = ImageFormat.Png; break;

                }

                pictureBox2.Image.Save(saveFileDialog.FileName, imageFormat);

            }

            

        }


        private void btnExit_Click(object sender, EventArgs e)

        {

            if (captureDeviceVideo.IsRunning)

            {

                captureDeviceVideo.SignalToStop();

                captureDeviceVideo.WaitForStop();

                pictureBox1.Image = null;

                pictureBox1.Invalidate();

                pictureBox2.Image = null;

                pictureBox2.Invalidate();

            }


            Application.Exit(null);

        }

    }

    

}

</div>


Komentar

Postingan populer dari blog ini

Final Project

Route & Controller in CodeIgniter

Fundamental Codeigniter (Tugas 8)