html5 canvas 画图片写文字

时间:15-08-01 栏目:html5/css3 作者:zongyan86 评论:0 点击: 3,367 次

直接贴代码,不解释:

/绘画图片
var canvas = document.getElementById('canvas'),
    ctx = canvas.getContext('2d');
var img = new Image();
img.onload = function(){
    var w = this.width,
    h = this.height;
    canvas.width = w;
    canvas.height = h;
    ctx.drawImage(this,0,0)
}
img.src = 'http://www.51kaola.com/wp-content/uploads/2014/07/kaola.gif';

//绘画文字
var canvas2 = document.getElementById('canvas2'),
    ctx2 = canvas2.getContext('2d');
ctx2.font = '30px Microsoft Yahei';
ctx2.fillStyle = '#dedede';
ctx2.fillText('kuaipao8.com',10,50);

web开发分享 



声明: 本文由( zongyan86 )原创编译,转载请保留链接: html5 canvas 画图片写文字

关注我们