HTML5.1 Canvas Context

In HTML5.1, the Canvas context will include some methods beyond toDataURL() and getContext().

supportsContext()

This method will allow a developer to test for support for different Canvas contexts in a web browser. In this book, we used the 2D context most of the time, but we added “experimental-wbgl” in this chapter, or “moz-3d.” In the future, the new Canvas context will be registered at this site.

toDataURLHD(), toBlob(), toBlobHD()

If you recall from earlier in the book, toDataURL() allows a developer to export a base64 encoded string that represents the Canvas display, which can then be converted to an image. This image is restricted to 96 dpi. In HTML5.1, this ability will be expanded to include several new variations:

toDataURLHD()

Returns canvas data at native resolution instead of 96 dpi

toBlob()

Returns data as a blob at 96 dpi instead of a base64 encoded string

toBlobHD()

Returns data as a blob at native resolution

Get HTML5 Canvas, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.