mirror of
https://github.com/konvajs/konva.git
synced 2026-03-03 16:58:33 +08:00
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
This commit is contained in:
25
src/Layer.js
25
src/Layer.js
@@ -107,6 +107,28 @@ Kinetic.Layer = Kinetic.Container.extend({
|
||||
getContext: function() {
|
||||
return this.context;
|
||||
},
|
||||
/**
|
||||
* Creates a composite data URL. If MIME type is not
|
||||
* specified, then "image/png" will result. For "image/jpeg", specify a quality
|
||||
* level as quality (range 0.0 - 1.0). Note that this method works
|
||||
* differently from toDataURL() for other nodes because it generates an absolute dataURL
|
||||
* based on what's draw on the layer, rather than drawing
|
||||
* the current state of each child node
|
||||
* @name toDataURL
|
||||
* @methodOf Kinetic.Stage.prototype
|
||||
* @param {String} [mimeType]
|
||||
* @param {Number} [quality]
|
||||
*/
|
||||
toDataURL: function(mimeType, quality) {
|
||||
try {
|
||||
// If this call fails (due to browser bug, like in Firefox 3.6),
|
||||
// then revert to previous no-parameter image/png behavior
|
||||
return this.getCanvas().toDataURL(mimeType, quality);
|
||||
}
|
||||
catch(e) {
|
||||
return this.getCanvas().toDataURL();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* private draw children
|
||||
*/
|
||||
@@ -121,7 +143,8 @@ Kinetic.Layer = Kinetic.Container.extend({
|
||||
}
|
||||
|
||||
if(this.attrs.clearBeforeDraw) {
|
||||
this.clear();
|
||||
var clearLayer = layer ? layer : this;
|
||||
clearLayer.clear();
|
||||
}
|
||||
|
||||
if(this.isVisible()) {
|
||||
|
||||
Reference in New Issue
Block a user