Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5404622
  • 博文数量: 763
  • 博客积分: 12108
  • 博客等级: 上将
  • 技术积分: 15717
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-28 21:21
个人简介

业精于勤,荒于嬉

文章分类

全部博文(763)

文章存档

2018年(6)

2017年(15)

2016年(2)

2015年(31)

2014年(14)

2013年(87)

2012年(75)

2011年(94)

2010年(190)

2009年(38)

2008年(183)

2007年(28)

分类: 系统运维

2011-07-05 12:09:51

drawImage 方法允许在 canvas 中插入其他图像
( img 和 canvas 元素) 。在 Opera 中可以再 canvas 中绘制 SVG 图形。此方法比较复杂,可以有3个、5个或9个参数

3个参数:最基本的 drawImage使用方法。一个参数指定图像位置,另两个参数设置图像在 canvas中的位置。
5个参数:中级的 drawImage 使用方法,包括上面所述3个参数,加两个参数指明插入图像宽度和高度 (如果你想改变图像大小)。
9个参数:最复杂 drawImage 杂使用方法,包含上述5个参数外,另外4个参数设置源图像中的位置和高度宽度。这些参数允许你在显示图像前动态裁剪源图像。

下面是上述三个使用方法的例子:

  • // Three arguments: the element, destination (x,y) coordinates.   
  • context.drawImage(img_elem, dx, dy);   
  • // Five arguments: the element, destination (x,y) coordinates, and destination     
  • // width and height (if you want to resize the source image).   
  • context.drawImage(img_elem, dx, dy, dw, dh);   
  • // Nine arguments: the element, source (x,y) coordinates, source width and     
  • // height (for cropping), destination (x,y) coordinates, and destination width     
  • // and height (resize).   
  • context.drawImage(img_elem, sx, sy, sw, sh, dx, dy, dw, dh);
阅读(1585) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~