jtopo实现导出图片

时间:2023-02-01 13:28:28

jtopo的功能还是比较全面的.

导出功能也比较简单

就一个函数调用.

基本可以覆盖以前svg原型的功能.

<!DOCTYPE html>
<html>
  <head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
	<title>jTopo Demo</title>
  <script type="text/javascript" src="js/jtopo-min.js"></script>
  </head>
 <body>  
    <input type="button" value="导出成PNG" onclick="exportPng()"/>
    <center>  
        <canvas width="800" height="500" id="canvas" style=" background-color:#EEEEEE; border:1px solid #444;">  
       
        </canvas>  
   </center> 
   	<script id='code'>

		
			var canvas = document.getElementById('canvas');			
			var stage = new JTopo.Stage(canvas);
			var scene = new JTopo.Scene(stage);
			stage.play(scene);
			
			var node = new JTopo.Node("Hello");							
			node.setLocation(300,200);
			scene.add(node);
			
			   	// 导出成PNG
		function exportPng(){
			stage.saveImageInfo();
		}
	</script> 
  </body>  
</html>