W3C Capture API our in draft
Author: Dion Almaer
9
Dec
A draft of the W3C Capture API has been put out there by the editors.
The Capture API defines a JavaScript API for accessing the microphone and camera of a hosting device.
When I look at the API for getting pictures from a camera I got a little scared at the amount of DOM fluff around the edges:
JAVASCRIPT:
-
-
// Create a container div element and append it to the document body.
-
var container = document.createElement("div");
-
document.body.appendChild(container);
-
-
// The browser viewport width in pixels.
-
var screenWidth = window.innerWidth;
-
-
function successCallback(data) {
-
for (var i in data) {
-
var img = document.createElement("img");
-
img.src = data[i].uri;
-
// If the image width exceeds that of the browser viewport, the image
-
// is scaled to fit the screen keeping the aspect ratio intact.
-
if (data[i].format.width> screenWidth) {
-
img.style.width = screenWidth + "px";
-
img.style.height = (data[i].format.height/data[i].format.width)*screenWidth + "px";
-
}
-
container.appendChild(img);
-
}
-
}
-
-
function errorCallback(err) {
-
alert(err.message + " (" + err.code + ")");
-
}
-
-
// Launch the device camera application and invoke the callback once
-
// the user exits the camera application.
-
transactionId = navigator.device.captureImage(successCallback, 1, errorCallback);
-
A lot of fluff for the transactionId = navigator.device.captureImage(successCallback, 1, errorCallback); meat.
What do you think of the API proposed?
Related News :