| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS implements CanvasImageS
ource$IMPLEMENTS$NATIVESPEC { | 7 $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS implements CanvasImageS
ource$IMPLEMENTS$NATIVESPEC { |
| 8 $!MEMBERS | 8 $!MEMBERS |
| 9 /** An API for drawing on this canvas. */ | 9 /** An API for drawing on this canvas. */ |
| 10 $if DART2JS | 10 $if DART2JS |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 'premultipliedAlpha': premultipliedAlpha, | 31 'premultipliedAlpha': premultipliedAlpha, |
| 32 'preserveDrawingBuffer': preserveDrawingBuffer, | 32 'preserveDrawingBuffer': preserveDrawingBuffer, |
| 33 }; | 33 }; |
| 34 var context = getContext('webgl', options); | 34 var context = getContext('webgl', options); |
| 35 if (context == null) { | 35 if (context == null) { |
| 36 context = getContext('experimental-webgl', options); | 36 context = getContext('experimental-webgl', options); |
| 37 } | 37 } |
| 38 return context; | 38 return context; |
| 39 } | 39 } |
| 40 | 40 |
| 41 String toDataUrl([String type = 'image/png', num quality]) => | 41 /** |
| 42 * Returns a data URI containing a representation of the image in the |
| 43 * format specified by type (defaults to 'image/png'). |
| 44 * |
| 45 * Data Uri format is as follow |
| 46 * `data:[<MIME-type>][;charset=<encoding>][;base64],<data>` |
| 47 * |
| 48 * Optional parameter [quality] in the range of 0.0 and 1.0 can be used when |
| 49 * requesting [type] 'image/jpeg' or 'image/webp'. If [quality] is not passed |
| 50 * the default value is used. Note: the default value varies by browser. |
| 51 * |
| 52 * If the height or width of this canvas element is 0, then 'data:' is |
| 53 * returned, representing no data. |
| 54 * |
| 55 * If the type requested is not 'image/png', and the returned value is |
| 56 * 'data:image/png', then the requested type is not supported. |
| 57 * |
| 58 * Example usage: |
| 59 * |
| 60 * CanvasElement canvas = new CanvasElement(); |
| 61 * var ctx = canvas.context2D |
| 62 * ..fillStyle = "rgb(200,0,0)" |
| 63 * ..fillRect(10, 10, 55, 50); |
| 64 * var dataUrl = canvas.toDataUrl("image/jpeg", 0.95); |
| 65 * // The Data Uri would look similar to |
| 66 * // 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA |
| 67 * // AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO |
| 68 * // 9TXL0Y4OHwAAAABJRU5ErkJggg==' |
| 69 * //Create a new image element from the data URI. |
| 70 * var img = new ImageElement(); |
| 71 * img.src = dataUrl; |
| 72 * document.body.children.add(img); |
| 73 * |
| 74 * See also: |
| 75 * |
| 76 * * [Data URI Scheme](http://en.wikipedia.org/wiki/Data_URI_scheme) from Wiki
pedia. |
| 77 * |
| 78 * * [HTMLCanvasElement](https://developer.mozilla.org/en-US/docs/DOM/HTMLCanv
asElement) from MDN. |
| 79 * |
| 80 * * [toDataUrl](http://dev.w3.org/html5/spec/the-canvas-element.html#dom-canv
as-todataurl) from W3C. |
| 81 */ |
| 82 String toDataUrl([String type = 'image/png', num quality]) => |
| 42 _toDataUrl(type, quality); | 83 _toDataUrl(type, quality); |
| 43 } | 84 } |
| OLD | NEW |