1 回答

TA貢獻1815條經(jīng)驗 獲得超6個贊
請試試這個:(你不需要獲取或放置圖像數(shù)據(jù))
你也正在做這樣的:ctx.putImageData(imageData, canvas.width, canvas.height);。這意味著您完全在畫布之外繪制圖像。改為這樣做:ctx.putImageData(imageData, 0,0);
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
let img = new Image();
img.onload = getIt
img.src = "download.png";
function getIt() {
canvas.width = this.width;
canvas.height = this.height;
//draw the image onto the canvas
ctx.drawImage(this, 0,0);
//use the data uri
test.src = canvas.toDataURL("image/png");
}
<img src="" id="test">
添加回答
舉報