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

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 UTC