W3C home > Mailing lists > Public > whatwg@whatwg.org > May 2012

Re: [whatwg] toDataURL() for image/video?

From: Glenn Maynard <glenn@zewt.org>
Date: Tue, 29 May 2012 13:55:08 -0500
Message-ID: <CABirCh_4af-Pgb=9vpv55x2c-dVV4Ze5q6wVWec5QqTA-JnP2Q@mail.gmail.com>
To: Ashley Gullen <ashley@scirra.com>
Cc: whatwg@lists.whatwg.org
On Tue, May 29, 2012 at 1:41 PM, Ashley Gullen <ashley@scirra.com> wrote:

> Has toDataURL() (from canvas) been considered for ordinary image and video
> elements?  Seems like it would be useful for pure javascript applications.
>  Currently it can be done by creating a new canvas, getting a 2D context,
> drawImage(), then canvas.toDataURL().  However adding it to images directly
> would be a useful convenience method, avoid the performance overhead of a
> new canvas, and probably be straightforward to define/implement.

It doesn't need any overhead, actually.  You can create a single canvas for
all of your readback operations.  As long as you keep the canvas out of the
document, it doesn't even need to actually blit the image; a smart
implementation can delay that, so when you read the data back it can get
the pixel data directly from the original image.  This is more important
with toBlob, where implementations might be able to skip the compression
step and just return the original compressed data.

> Use cases for myimage.toDataURL():

(These are use cases for reading back images--they're not really use cases
for adding another way to do it.)

Glenn Maynard
Received on Tuesday, 29 May 2012 18:55:46 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:42 UTC