W3C home > Mailing lists > Public > public-device-apis@w3.org > December 2009

Re: First stab at the Capture API (aka Camera API)

From: Robin Berjon <robin@robineko.com>
Date: Fri, 4 Dec 2009 15:52:05 +0100
Cc: public-device-apis <public-device-apis@w3.org>
Message-Id: <22011BE5-D10B-4ED9-975D-6D048C3DDA9D@robineko.com>
To: Ilkka Oksanen <Ilkka.Oksanen@nokia.com>
On Dec 4, 2009, at 15:23 , Ilkka Oksanen wrote:
> To keep things simple in v1.0 most of the configuration could happen
> through UI in native side. Resolution (and quality) setting is a special
> case in a sense that it affects directly to the file size. Following
> could happen more often if there is no way of hinting the preffered
> resolution in the API.
> 
> - A widget allows user to set profile picture, max resolution is
>   640x480
> - Native camera has the default resolution of 1600x1200
> - User doesn't change resolution and takes the profile image
> - Widget uploads the image to server
> - Server shrinks the image -> Bandwith wasted.

There's an API for that!

You would:

  - get the image somehow
  - assign it to an <img> element (visible or not); alternatively, get a way of extracting HTML5 ImageData from it)
  - if it's the right size or less, you're good, otherwise continue
  - create a canvas element of the desired size, get its 2D context
  - use c2d.drawImage(yourImg, 0, 0, width, height) (or putImageData if you have ImageData)
  - then return c2d.getImageData(), or c2d.toDataURL(), or whatever newish thing that can return properly encoded image content

Not perfect, but workable.

--
Robin Berjon
  robineko  hired gun, higher standards
  http://robineko.com/
Received on Friday, 4 December 2009 14:52:36 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 9 May 2012 00:14:02 GMT