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:
  1.  
  2. // Create a container div element and append it to the document body.
  3. var container = document.createElement("div");
  4. document.body.appendChild(container);
  5.  
  6. // The browser viewport width in pixels.
  7. var screenWidth = window.innerWidth;
  8.  
  9. function successCallback(data) {
  10.   for (var i in data) {
  11.   var img = document.createElement("img");
  12.   img.src = data[i].uri;
  13.   // If the image width exceeds that of the browser viewport, the image
  14.   // is scaled to fit the screen keeping the aspect ratio intact.
  15.     if (data[i].format.width> screenWidth) {
  16.       img.style.width = screenWidth + "px";
  17.       img.style.height = (data[i].format.height/data[i].format.width)*screenWidth + "px";
  18.     }
  19.     container.appendChild(img);
  20.   }
  21. }
  22.  
  23. function errorCallback(err) {
  24.   alert(err.message + " (" + err.code + ")");
  25. }
  26.  
  27. // Launch the device camera application and invoke the callback once
  28. // the user exits the camera application.
  29. transactionId = navigator.device.captureImage(successCallback, 1, errorCallback);
  30.  

A lot of fluff for the transactionId = navigator.device.captureImage(successCallback, 1, errorCallback); meat.

What do you think of the API proposed?


Related News :