Latihan 3 PBKK (A)

 Nama : Tsaqif Deniar B.

NRP : 5025211151

Kelas : PBKK (A)


LATIHAN 3


Latihan 2 pada kelas PBKK yaitu membuat applikasi Video Capture sederhana dengan menggunakan bahasa C# pada IDE yang dijalankan oleh .NET Framework. Implementasi aplikasi Windows Forms yang memanfaatkan Library AForge.NET Framework untuk berinteraksi dengan webcam. Dimana applikasi ini memiliki fungsi fitur yang pertama mengambil gambar dari source yang ditentutkan misalkan webcam bawaan laptop, yang kedua applikasi bisa mengcapture gambar lalu menyimpan gambar berupa png pada lokasi yang ditentukan.


Berikut dokumentasi hasil program :





Dan berikut hasil capture dari app tersebut :

Berikut Source Code program tersebut :

using AForge;
using AForge.Video;
using AForge.Video.DirectShow;
using System.Drawing;
using System.Drawing.Imaging;
namespace WebcamCapture
{
public partial class Form1 : Form
{
private FilterInfoCollection captureDevice;
private VideoCaptureDevice videoSource;
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
captureDevice = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo deviceList in captureDevice)
{
comboBoxWebcamList.Items.Add(deviceList.Name);
}
comboBoxWebcamList.SelectedIndex = 0;
videoSource = new VideoCaptureDevice();
}
private void buttonStart_Click(object sender, EventArgs e)
{
if (videoSource.IsRunning)
{
videoSource.SignalToStop();
videoSource.WaitForStop();
pictureBox1.Image = null;
pictureBox1.Invalidate();
}
videoSource = new VideoCaptureDevice(captureDevice[comboBoxWebcamList.SelectedIndex].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(VideoSource_NewFrame);
videoSource.Start();
}
private void VideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
}
private void buttonCapture_Click(object sender, EventArgs e)
{
pictureBox2.Image = (Bitmap)pictureBox1.Image.Clone();
}
private void buttonSaveImg_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 buttonExit_Click(object sender, EventArgs e)
{
if (videoSource.IsRunning)
{
videoSource.SignalToStop();
videoSource.WaitForStop();
pictureBox1.Image = null;
pictureBox1.Invalidate();
pictureBox2.Image = null;
pictureBox2.Invalidate();
}
Application.Exit(null);
}
}
}
view raw AppVideoCapture hosted with ❤ by GitHub

Comments

Popular posts from this blog

Latihan 10 PBKK (A)

Pemrograman Perangkat Bergerak (D) - Pertemuan 2

Quiz 1 PBKK (A)