TUGAS PERTEMUAN KE-2 [MEDIA CAPTURE]
Media capture adalah proses pengambilan atau perekaman berbagai jenis media, seperti gambar, audio, atau video, menggunakan perangkat keras seperti kamera, mikrofon, atau sensor lainnya. Dalam konteks pengembangan perangkat lunak dengan framework .NET, media capture mengacu pada penggunaan perangkat lunak untuk mengendalikan perangkat keras ini dan mengambil data media dari mereka. Framework .NET adalah rangkaian alat, perpustakaan, dan teknologi yang dikembangkan oleh Microsoft untuk membangun berbagai jenis aplikasi, termasuk aplikasi desktop, aplikasi web, dan aplikasi seluler.
Beberapa contoh penggunaan media capture dalam konteks framework .NET adalah:
- Pengambilan Gambar: Kita dapat menggunakan framework .NET untuk mengakses kamera pada perangkat, baik itu kamera web pada komputer atau kamera pada perangkat seluler, dan mengambil gambar dari kamera tersebut.
- Perekaman Audio: Kita dapat menggunakan framework .NET untuk merekam suara dari mikrofon perangkat dan menyimpannya dalam berbagai format file audio.
- Perekaman Video: Framework .NET juga memungkinkan kita untuk mengambil video dari kamera perangkat dan menyimpannya dalam format yang sesuai.
- Pengambilan Data Sensor: Selain itu, kita juga dapat menggunakan framework .NET untuk mengakses data dari berbagai sensor seperti akselerometer, giroskop, atau sensor lainnya pada perangkat.
- Pengolahan Media: Setelah media diambil, kita dapat menggunakan framework .NET untuk melakukan berbagai operasi pemrosesan, seperti penyuntingan gambar atau video, pemrosesan audio, dan analisis data sensor.
User Interface :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using AForge; | |
using AForge.Video; | |
using AForge.Video.DirectShow; | |
using System.Drawing; | |
using System.Drawing.Imaging; | |
namespace VideoCapture | |
{ | |
public partial class Form1 : Form | |
{ | |
private FilterInfoCollection captureDevice; | |
private VideoCaptureDevice videoSource; | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
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 start_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 capture_Click(object sender, EventArgs e) | |
{ | |
pictureBox2.Image = (Bitmap)pictureBox1.Image.Clone(); | |
} | |
private void SaveImage_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 Exit_Click(object sender, EventArgs e) | |
{ | |
if (videoSource.IsRunning) | |
{ | |
videoSource.SignalToStop(); | |
videoSource.WaitForStop(); | |
pictureBox1.Image = null; | |
pictureBox2.Image= null; | |
pictureBox1.Invalidate(); | |
pictureBox2.Invalidate(); | |
} | |
Application.Exit(null); | |
} | |
} | |
} |
Comments
Post a Comment