[ html drawImage 绘制图片 ] canvas绘制图片 drawImage 属性实例演示之二

 1 <!DOCTYPE html>
 2 <html lang=‘zh-cn‘>
 3 <head>
 4 <title>Insert you title</title>
 5 <meta name=‘description‘ content=‘this is my page‘>
 6 <meta name=‘keywords‘ content=‘keyword1,keyword2,keyword3‘>
 7 <meta http-equiv=‘Content-Type‘ content=‘text/html; charset=utf-8‘>
 8 <link rel=‘stylesheet‘ type=‘text/css‘ href=‘./css/index.css‘ />
 9 <script type=‘text/javascript‘ src=‘./js/jquery-1.12.1.min.js‘></script>
10 <style type=‘text/css‘>
11 html,body {
12     margin: 0; padding: 0;
13 }
14
15 html {
16     height: 100%;
17 }
18
19 body {
20     background: #000;
21 }
22
23 #can {
24     background: #FFF; display: block; margin: 25px auto; border-radius: 2px;
25 }
26
27 img {
28     -moz-user-select: none;
29 }
30 </style>
31 <script type=‘text/javascript‘>
32     var oCan = null;
33     var oImg = null;
34     $( function(){
35         oCan = $( ‘#can‘ ).get( 0 ).getContext( ‘2d‘ );
36         /* 在这里需要注意的就是我们的drawImg()不能将其放置在jquery中,因为jquery的$(document).ready(function(){})有等待页面加载完成之后在加载JS文件的功效,而我们又告诉HTML文档要预加载图片所以他们无法同时使用: 报错内容是drawImg()为define*/
37         oImg = $( ‘img‘ ).get( 0 );
38     } );
39     function drawImg(){
40         oCan.drawImage( oImg , 0 , 0 , oImg.width , oImg.height );
41     }
42 </script>
43 </head>
44 <body onload=‘drawImg()‘>
45     <canvas id=‘can‘ width=‘500‘ height=‘450‘>您的浏览器版本过低请升级您的浏览器以获取更好的用户体验...</canvas>
46     <img src=‘./images/demoImg.jpg‘ width=‘25%‘ height=‘15%‘ />
47 </body>
48 </html>
时间: 2024-10-23 13:18:27

[ html drawImage 绘制图片 ] canvas绘制图片 drawImage 属性实例演示之二的相关文章

[ html canvas save restore ] canvas绘图 save restore 属性实例演示

解析: 我们可以在做平移变换之前将当前canvas的状态进行保存,其实Canvas为 我们提供了图层(Layer)的支持,而这些Layer(图层)是按"栈结构"来进行管理的 当我们调用save()方法,会保存当前Canvas的状态然后作为一个Layer(图层),添加到Canvas栈中, 另外,这个Layer(图层)不是一个具体的类,就是一个概念性的东西而已! 而当我们调用restore()方法的时候,会恢复之前Canvas的状态,而此时Canvas的图层栈 会弹出栈顶的那个Layer,

[ html drawImage 绘制图片 ] canvas绘制图片 drawImage 属性实例演示

<!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title> <meta name='description' content='this is my page'> <meta name='keywords' content='keyword1,keyword2,keyword3'> <meta http-equiv="

[ html drawImage 图片预加载 ] canvas绘制图片 drawImage 属性实例演示之三--使用New Image()进行图片预加载

1 <!DOCTYPE html> 2 <html lang='zh-cn'> 3 <head> 4 <title>Insert you title</title> 5 <meta name='description' content='this is my page'> 6 <meta name='keywords' content='keyword1,keyword2,keyword3'> 7 <meta htt

[ html canvas 绘制曲线三种方法 ] canvas绘图 绘制曲线三种方法属性实例演示

1 <!DOCTYPE html> 2 <html lang='zh-cn'> 3 <head> 4 <title>Insert you title</title> 5 <meta name='description' content='this is my page'> 6 <meta name='keywords' content='keyword1,keyword2,keyword3'> 7 <meta htt

[ html canvas 绘制文本 ] canvas绘图实现绘制文本 strokeText fillText方法及textAlign textBaseline font 属性实例演示

1 <!DOCTYPE html> 2 <html lang='zh-cn'> 3 <head> 4 <title>Insert you title</title> 5 <meta name='description' content='this is my page'> 6 <meta name='keywords' content='keyword1,keyword2,keyword3'> 7 <meta htt

[ html canvas 旋转 缩放 平移 ] canvas绘图实现旋转复制实例演示

<!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title> <meta name='description' content='this is my page'> <meta name='keywords' content='keyword1,keyword2,keyword3'> <meta http-equiv="

[ html canvas quadraticCurveTo ] canvas绘图quadraticCurveTo()属性研究实例演示之二

1 <!DOCTYPE html> 2 <html lang='zh-cn'> 3 <head> 4 <title>Insert you title</title> 5 <meta name='description' content='this is my page'> 6 <meta name='keywords' content='keyword1,keyword2,keyword3'> 7 <meta htt

[ html 绘图 translate ] canvas绘图属性translate 设置画布中心点属性实例演示

1 <!DOCTYPE html> 2 <html lang='zh-cn'> 3 <head> 4 <title>Insert you title</title> 5 <meta name='description' content='this is my page'> 6 <meta name='keywords' content='keyword1,keyword2,keyword3'> 7 <meta htt

[ html canvas arcTo ] canvas绘图 arcTo()属性研究实例演示之二

1 <!DOCTYPE html> 2 <html lang='zh-cn'> 3 <head> 4 <title>Insert you title</title> 5 <meta name='description' content='this is my page'> 6 <meta name='keywords' content='keyword1,keyword2,keyword3'> 7 <meta htt