Sup*_*iji 5 html javascript canvas
我知道我可以使用 javascript 做到这一点:
var ctx = getCanvas('testCanvas').getContext('2d'); // get Canvas context
var img = new Image();
img.src = 'test.png';
img.onload = function(){
ctx.drawImage(img, 200, 200); // x, y, width, height
}
Run Code Online (Sandbox Code Playgroud)
但是如何将现有标签绘制到画布上:
在 HTML 中:
<img src='test.png'>
Run Code Online (Sandbox Code Playgroud)
为什么我要这样做?我想使用 pagespeed 优化图像加载
你的问题的第一个谷歌点击是有希望的:
var c=document.getElementById("testCanvas");
var ctx=c.getContext("2d");
var img=document.getElementById("existingHTMLImageElementId");
ctx.drawImage(img,10,10);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1875 次 |
| 最近记录: |