-
İçerikler özgün değildir. Sadece sık sık lazım olan işime yarayacak olan notları almış olduğum kişisel bloğumdur.
8 Şubat 2014 Cumartesi
Camera and Video Control with HTML5
Client-side APIs on mobile and desktop devices are quickly providing the same APIs. Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop. One of those APIs is the getUserMedia API, providing developers access to the user's camera. Let me show you how to get simple camera access from within your browser!
The HTML
Please read my note about the HTML structure below:
<!--
Ideally these elements aren't created until it's confirmed that the
client supports video/camera, but for the sake of illustrating the
elements involved, they are created with markup (not JavaScript)
-->
<video id="video" width="640" height="480" autoplay></video>
<button id="snap">Snap Photo</button>
<canvas id="canvas" width="640" height="480"></canvas>
Each of these elements should be created once confirmation of camera support is confirmed, but for the sake of this tutorial, I wanted to show you what the elements look like with basic HTML. Do note that the dimensions we're working with are 640x480.
The JavaScript
Since the HTML elements above are already created, the JavaScript portion will look smaller than you think:
// Put event listeners into place
window.addEventListener("DOMContentLoaded", function() {
// Grab elements, create settings, etc.
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
video = document.getElementById("video"),
videoObj = { "video": true },
errBack = function(error) {
console.log("Video capture error: ", error.code);
};
// Put video listeners into place
if(navigator.getUserMedia) { // Standard
navigator.getUserMedia(videoObj, function(stream) {
video.src = stream;
video.play();
}, errBack);
} else if(navigator.webkitGetUserMedia) { // WebKit-prefixed
navigator.webkitGetUserMedia(videoObj, function(stream){
video.src = window.webkitURL.createObjectURL(stream);
video.play();
}, errBack);
}
else if(navigator.mozGetUserMedia) { // Firefox-prefixed
navigator.mozGetUserMedia(videoObj, function(stream){
video.src = window.URL.createObjectURL(stream);
video.play();
}, errBack);
}
}, false);
Once it's been established that the browser supports getUserMedia, a simple method sets the video element's src to the user's live camera/webcam. Calling the play method of the video then enacts the element's live video connection. That's all that's required to connect your camera to the browser!
Taking a photo is only marginally more difficult. Simply add a click listener to a generic button and and draw an image from video!
// Trigger photo take
document.getElementById("snap").addEventListener("click", function() {
context.drawImage(video, 0, 0, 640, 480);
});
Of course you could add some sexy image filters and make a billion dollars...but I'll save that for another post. At minimum you could convert the canvas snapshot to an image though! I'll talk about canvas image filters in the future...
Being able to access the camera within the browser without using third party software is an incredible advancement. Paired with canvas and a bit of JavaScript, the camera has become quickly and easily accessible. Not only it the camera accessible, but since canvas is ultra-flexible, we'll be able to add sexy Instagram-style image filters in the future. For now, however, simply accessing the camera in our browser moves us miles ahead. Have fun taking images within your browser!
Post inspired by I see you getUserMedia; provided a great starting point for this post.
Related Posts
Kaydol:
Kayıt Yorumları
(
Atom
)
search this website
email updates
Like us on facebook
Katkıda bulunanlar
Blogger tarafından desteklenmektedir.
Etiketler
- AJAX (3)
- alertbox (1)
- android (1)
- Asp.net (22)
- blogger (1)
- bootstrap (2)
- C# (1)
- Canvas (3)
- capture (2)
- datetime (1)
- dizüstü (1)
- dizüstü bilgisayardan interneti paylaştırmak (1)
- editör yapma (1)
- facebook api (1)
- Flash (1)
- format (1)
- geometri (6)
- google (1)
- Graf (1)
- Graf Teorisi (1)
- Hatalar (4)
- Html (1)
- html5 (2)
- iframe (1)
- ilköğretim (4)
- javascript (2)
- jquery (7)
- JSON (2)
- kablosuz (1)
- Karakter (1)
- Kodlama örnekleri (2)
- kütle (4)
- Laravel (2)
- laravel g-zip (1)
- Listbox (1)
- Matematik (20)
- matematikistan (2)
- matematikistan.net (16)
- mongoDB (1)
- msdos (1)
- mysql (4)
- netbeans (1)
- phonegap (1)
- php (3)
- php ile benzer tags (1)
- php similar tags (1)
- routing (2)
- Samsung (1)
- Save (1)
- Save Canvas (2)
- SOAP (1)
- tags (1)
- tarih (1)
- Thumbnail (1)
- Türkçe (1)
- türkçe karakter (1)
- Türksat 4A (1)
- url routing (2)
- utf-8 (1)
- Validation Kontrolleri (3)
- wifi (1)
- WYSIWYG (1)
- WYSIWYG editör (1)
- xml (1)
İşe Yarar Siteler
Blog Archive
-
2014
(91)
- Aralık (1)
- Kasım (4)
- Ekim (9)
- Eylül (5)
- Ağustos (3)
- Nisan (1)
- Mart (20)
-
Şubat
(28)
- asp.net hata ve çözümleri
- Link Değişimi Page Rank Değerini yükseltme
- Bu site bilgisayarınıza zarar verebilir – JavaScri...
- Youtube Videolarından Küçük Resim Çekmek
- Asp.Net de İç İçe Repeater Kullanımı
- Asp.net String İşlemleri
- Asp.net ikili listbox
- Asp.Net Listbox Text ve Value Ekleme
- JQuery Seçiciler ve Filtreler
- ASP.NET Rastgele Sayı ve Harf Üretme
- Ajax Get ve POST methodu ile XMLHTTPRequest
- Bilgisayar Donanımlı Ortamda Fonksiyon ve Graf
- Asp.net ile başka sitenin görüntüsünü alma(Thumbnail)
- Asp.Net ile ekran görüntüsü yakalama(printscreen)
- JavaScript Canvas Image Conversion
- Camera and Video Control with HTML5
- Jquery ile sayfa yükleniyor gifi
- Kısa Flash Notları
- ASP.NET ScriptService
- jquery click event
- Matematikistan.net
- Fraktal ve Fraktal Geometri Nedir
- javascript-hata-bulma-ve-sikistirma-javascript-com...
- Asp.Net Gzip ile Sayfa Sıkıştırma
- Validation hata mesajlarını alertbox ile gösterme
- Asp.net validition karşılaşılan hatalar
- IFrame İçerisindeki Veriye JavaScript ile Erişme
- Asp.Net Canvas Resim Kaydetme
- Ocak (20)
Popular Posts
-
Dosyaya erişim izni verme sudo chmod -R 777 /home/sixven/camp_sms/inputs
-
How to delete, disable and exit Demo Live Unit Retail Mode on the Samsung Galaxy S5 1. The first thing to do is to disable the retail mod...
-
Facebook uygulama geliştirirken bu tarz bir hata aldım. Çözümü : 1) https://developers.facebook.com sayfasından uygulamanın “Settings” ...
-
Öncelikle http://htmlagilitypack.codeplex.com/ sitesinden Html Agility Pack i indiriyoruz sonra projemizde sağ üstdeki solution ex...
-
Localhost için Choreme Eklentisi = Eklenti Sunucu Taraflı çalışmalarda ise php dosyasının en üstüne aşağıdakileri ekleyebilirsiniz: he...
-
TCPDF de font türkçe destekli bile olsa zaman zaman sıkıntı yaratabiliyor. Yapılacak işlemler şunlar 1- http://fonts.snm-portal.com/ fon...
-
Alıntı:http://www.zafercelenk.net/post/2010/06/23/SQL-ile-Kay%C4%B1tlar%C4%B1-Sayal%C4%B1m.aspx Geliştirdiğiniz uygulamalarda veritabanı...
-
başlat>çalıştır>regedit burdan aşağıdaki değerleri silin; HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\De...
-
Kaynak: https://www.zdaylan.com/c-system-tray-uygulamayi-gorev-cubugunda-calistirma/ formun özelliklerinden ShowInTaskbar Özelliğini Fal...
-
GsmComm kütüphanesiyle SMS Göndermek ve SMS Okumak Önce telefonunuzu bilgisayarınıza USB veya Bluetooth ile bağlayın. Telefonunuzun ...
© Arif Erzin Bloğu-Kendime Notlar 2013 . Powered by Bootstrap , Blogger templates and RWD Testing Tool
Hiç yorum yok :
Yorum Gönder