HTML5画布阶段数据与KineticJS URL
2014-01-04 16:09
281 查看
获取数据的URL KineticJS的阶段,我们可以使用toDataURL()方法需要一个回调函数。此外,我们也可以传入一个mime类型如图像/ jpeg和质量范围在0和1之间的值。我们也可以获得数据的url的特定节点,包括层、组和形状。
注意:toDataURL()方法要求任何图像绘制到画布上驻留在web服务器上使用相同的域代码执行。如果不满足此条件,SECURITY_ERR抛出异常。
说明:拖放矩形,然后单击save按钮获得复合数据url和打开生成的图像在一个新的窗口
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
#buttons {
position: absolute;
left: 10px;
top: 0px;
}
button {
margin-top: 10px;
display: block;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<button id="save">
Save as image
</button>
</div>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.7.4.min.js"></script>
<script defer="defer">
var stage = new Kinetic.Stage({
container: 'container',
width: 578,
height: 200
});
var layer = new Kinetic.Layer();
var rectX = stage.getWidth() / 2 - 50;
var rectY = stage.getHeight() / 2 - 25;
var box = new Kinetic.Rect({
x: rectX,
y: rectY,
width: 100,
height: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
draggable: true
});
box.on('mouseover', function() {
document.body.style.cursor = 'pointer';
});
box.on('mouseout', function() {
document.body.style.cursor = 'default';
});
layer.add(box);
stage.add(layer);
document.getElementById('save').addEventListener('click', function() {
/*
* since the stage toDataURL() method is asynchronous, we need
* to provide a callback
*/
stage.toDataURL({
callback: function(dataUrl) {
/*
* here you can do anything you like with the data url.
* In this tutorial we'll just open the url with the browser
* so that you can see the result as an image
*/
window.open(dataUrl);
}
});
}, false);
</script>
</body>
</html>
注意:toDataURL()方法要求任何图像绘制到画布上驻留在web服务器上使用相同的域代码执行。如果不满足此条件,SECURITY_ERR抛出异常。
说明:拖放矩形,然后单击save按钮获得复合数据url和打开生成的图像在一个新的窗口
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
#buttons {
position: absolute;
left: 10px;
top: 0px;
}
button {
margin-top: 10px;
display: block;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<button id="save">
Save as image
</button>
</div>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.7.4.min.js"></script>
<script defer="defer">
var stage = new Kinetic.Stage({
container: 'container',
width: 578,
height: 200
});
var layer = new Kinetic.Layer();
var rectX = stage.getWidth() / 2 - 50;
var rectY = stage.getHeight() / 2 - 25;
var box = new Kinetic.Rect({
x: rectX,
y: rectY,
width: 100,
height: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
draggable: true
});
box.on('mouseover', function() {
document.body.style.cursor = 'pointer';
});
box.on('mouseout', function() {
document.body.style.cursor = 'default';
});
layer.add(box);
stage.add(layer);
document.getElementById('save').addEventListener('click', function() {
/*
* since the stage toDataURL() method is asynchronous, we need
* to provide a callback
*/
stage.toDataURL({
callback: function(dataUrl) {
/*
* here you can do anything you like with the data url.
* In this tutorial we'll just open the url with the browser
* so that you can see the result as an image
*/
window.open(dataUrl);
}
});
}, false);
</script>
</body>
</html>
相关文章推荐
- HTML5画布加载图像数据的URL
- HTML5画布kineticjs BLOB教程
- HTML5画布获得图像数据的URL
- HTML5画布加载图像数据的URL
- 用js通过url传参把数据从一个页面传到另一个页面
- 使用HTML5画布实现的超棒javascript动画仪表板:gauge.js
- 使用HTML5画布实现的超棒javascript动画仪表板:gauge.js
- HTML5里面的东西:Canvas KineticJS规模动画教程!
- 用js通过url传参把数据从一个页面传到另一个页面
- HTML5画布WebGL,文件Three.js控制的锥
- 【Node.js-1】NodeJS简单入门、http、fs、url、querystring、接收客户端get/post数据
- JS获取url中传递的数据的三种方法
- 推荐的html5知识:Canvas KineticJS图片教程!
- js获取Url后的数据转换为json
- oracle下修改列顺序、显示CLOB数据|js 取得url
- HTML5又一个点:Canvas KineticJS文本教程!
- HTML5画布阅读Three js Phong材料
- HTML5 画布上的 Three.js 环境灯光(HTML5 Canvas Three.js Ambient Lighting)
- 前端 JS,localStorage/sessionStorage、cookie 及 url 等实现前台数据共享、传输
- js中对arry数组的各种操作小结 瀑布流AJAX无刷新加载数据列表--当页面滚动到Id时再继续加载数据 web前端url传递值 js加密解密 HTML中让表单input等文本框为只读不可编辑的方法 js监听用户的键盘敲击事件,兼容各大主流浏览器 HTML特殊字符