久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

html5 - canvas 跨域問題

瀏覽:125日期:2023-01-11 15:52:17

問題描述

在微信上給用戶修改頭像的時候,用canvas來截圖。結果報錯:Owechat_login.js:226 Uncaught TypeError: Failed to execute ’getImageData’ on ’CanvasRenderingContext2D’: The provided double value is non-finite.代碼:function cropImage(targetCanvas, x, y, width, height) {

var targetctx = targetCanvas.getContext(’2d’);var targetctxImageData = targetctx.getImageData(x, y, width, height); // sx, sy, sWidth, sHeight var c = document.createElement(’canvas’);var ctx = c.getContext(’2d’); c.width = width;c.height = height; ctx.rect(0, 0, width, height);ctx.fillStyle = ’white’;ctx.fill();ctx.putImageData(targetctxImageData, 0, 0); // imageData, dx, dy document.getElementById(’image’).src = c.toDataURL(’image/jpeg’, 0.92);document.getElementById(’image’).style.display = ’initial’; }

問題解答

回答1:

初步看了下代碼貌似沒什么問題的,排除掉圖片可能存在的跨域問題,還有一個問題樓主可以查看下就是getImageData 的傳參,需要是number類型,樓主可以先使用

console.log(typeof x, typeof y, typeof width, typeof height)

來看看

回答2:

應該不是跨域吧,跨域會寫 The canvas has been tainted by cross-origin data

console.log一下getImageData的參數吧。The provided double value is non-finite有可能是吧string當數傳進來了。

標簽: Html5
相關文章:
主站蜘蛛池模板: 和龙市| 梅州市| 湾仔区| 宣化县| 上犹县| 皮山县| 乌拉特前旗| 望谟县| 凤翔县| 茌平县| 呼伦贝尔市| 屯留县| 翼城县| 永泰县| 邢台市| 德庆县| 营口市| 吉隆县| 砀山县| 临高县| 洞头县| 资溪县| 米脂县| 寻甸| 金乡县| 噶尔县| 刚察县| 台南市| 鄂托克前旗| 龙海市| 诸城市| 南康市| 荆州市| 武冈市| 石门县| 库伦旗| 汉源县| 肇州县| 平乡县| 察雅县| 淮滨县|