Trip to Canvas(2 - 图片处理)
2010-07-05 20:14
197 查看
上一篇文章中简单的举了2个canvas的例子,这里对canvas的画图进一步学习。
IE8或以下不支持!
图片重叠阴影
var g = document.getElementById("canvas1").getContext("2d");
g.fillStyle = "#c80000";
g.fillRect(10, 10, 55, 50);
g.fillStyle = "rgba(0, 0, 200, 0.5)";
g.fillRect(30, 30, 55, 50);
Run
曲线
var g = document.getElementById("canvas2").getContext("2d");
g.shadowBlur = 30;
g.shadowBlur = 30;
g.fillStyle = "red";
g.beginPath();
g.moveTo(30, 30);
g.lineTo(150, 150);
g.bezierCurveTo(60, 70, 60, 70, 70, 150);
g.lineTo(30, 30);
g.fill();
Run
Image repeat
Repeat the images:
var g = document.getElementById("canvas4").getContext("2d");
var img = new Image();
img.onload = function() {
for (i = 0; i < 4; i++) {
for (j = 0; j < 3; j++) {
g.drawImage(img, j * 50, i * 38, 50, 38);
}
}
}
img.src = 'http://images.cnblogs.com/cnblogs_com/whoseyourlady/251987/r_repaste.jpg';
Run
Change the numbers in line6 and re-run
Image frame
The images used are as follows:
Add frame to images:
var g = document.getElementById("canvas3").getContext("2d");
g.shadowBlur = 30;
g.drawImage(document.getElementById('source'), 68, 21, 350, 125, 20, 20, 87, 104);
g.drawImage(document.getElementById('frame'), 0, 0);
Run
Change the third line to g.drawImage(document.getElementById('source'), 68, 21, 150, 125, 20, 20, 87, 104); and re-run
Change the other numbers and re-run
IE8或以下不支持!
图片重叠阴影
var g = document.getElementById("canvas1").getContext("2d");
g.fillStyle = "#c80000";
g.fillRect(10, 10, 55, 50);
g.fillStyle = "rgba(0, 0, 200, 0.5)";
g.fillRect(30, 30, 55, 50);
Run
曲线
var g = document.getElementById("canvas2").getContext("2d");
g.shadowBlur = 30;
g.shadowBlur = 30;
g.fillStyle = "red";
g.beginPath();
g.moveTo(30, 30);
g.lineTo(150, 150);
g.bezierCurveTo(60, 70, 60, 70, 70, 150);
g.lineTo(30, 30);
g.fill();
Run
Image repeat
Repeat the images:
var g = document.getElementById("canvas4").getContext("2d");
var img = new Image();
img.onload = function() {
for (i = 0; i < 4; i++) {
for (j = 0; j < 3; j++) {
g.drawImage(img, j * 50, i * 38, 50, 38);
}
}
}
img.src = 'http://images.cnblogs.com/cnblogs_com/whoseyourlady/251987/r_repaste.jpg';
Run
Change the numbers in line6 and re-run
Image frame
The images used are as follows:
Add frame to images:
var g = document.getElementById("canvas3").getContext("2d");
g.shadowBlur = 30;
g.drawImage(document.getElementById('source'), 68, 21, 350, 125, 20, 20, 87, 104);
g.drawImage(document.getElementById('frame'), 0, 0);
Run
Change the third line to g.drawImage(document.getElementById('source'), 68, 21, 150, 125, 20, 20, 87, 104); and re-run
Change the other numbers and re-run
相关文章推荐
- Android手动回收bitmap,引发Canvas: trying to use a recycled bitmap处理
- 基于canvas的图片反色处理
- 利用HTML5 canvas合并图片并解决Filaed to execute 'toDataURL' on 'HTMLCanvasElement'异常
- [javascript] <完全开源,开心分享> HTML5 Canvas 在线图片处理《imageMagic》(single page app)开发详解[1]
- Android手动回收bitmapisRecycled(),引发Canvas: trying to use a recycled bitmap处理
- canvas(11/30)--------事件处理(局部图片放大)
- 利用HTML5中Canvas处理并存储图片
- 用Canvas玩图片处理
- CANVAS实现图片模糊(处理库StackBlur.js)
- canvas学习笔记:canvas对图片的像素级处理--ImageData的应用
- Android手动回收bitmap,引发Canvas: trying to use a recycled bitmap处理
- Gesture控制图片缩放&Canvas: trying to use a recycled bitmap android.graphics.Bitmap异常
- canvas处理图片为圆形或圆角矩形
- 基于canvas图像处理的图片 灰色图像
- Android的SwipeToDismiss第三方开源框架模拟QQ对话列表侧滑删除,置顶,将头像图片圆形化处理。
- Immutable bitmap passed to Canvas constructor错误处理
- 用Canvas+Javascript FileAPI 实现一个跨平台的图片剪切、滤镜处理、上传下载工具
- 基于canvas图像处理的图片展示demo
- html5 canvas 加载图片错误 SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement'
- canvas的处理图片功能