{"id":3241,"date":"2021-04-25T08:46:43","date_gmt":"2021-04-25T00:46:43","guid":{"rendered":"http:\/\/www.yuguoxy.com\/geekhome\/?p=3241"},"modified":"2021-04-25T08:56:20","modified_gmt":"2021-04-25T00:56:20","slug":"%e7%94%9f%e6%88%90%e5%89%8d%e7%ab%af%e6%b5%b7%e6%8a%a5%e7%9a%84-n-%e7%a7%8d%e6%96%b9%e6%a1%88%e5%92%8c%e4%bc%98%e5%8a%a3","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=3241","title":{"rendered":"\u751f\u6210\u524d\u7aef\u6d77\u62a5\u7684 N \u79cd\u65b9\u6848\u548c\u4f18\u52a3"},"content":{"rendered":"<h2>\u4e00\u3001\u80cc\u666f<\/h2>\n<blockquote><p>\u5de5\u4f5c\u4e2d\u505a\u4e86\u5f88\u591a\u751f\u6210\u6d77\u62a5\u7684\u529f\u80fd\uff0c\u4e0d\u540c\u9700\u6c42\uff0c\u4e0d\u540c\u573a\u666f\uff0c\u4f7f\u7528\u4e86\u51e0\u79cd\u65b9\u6848\uff0c\u5404\u6709\u4f18\u52a3\u3002\u4e00\u76f4\u60f3\u8981\u6574\u7406\u4e00\u4e0b\uff0c\u4f46\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\u7684\u601d\u8003\u548c\u9047\u5230\u7684\u95ee\u9898\u6ca1\u6709\u8bb0\u5f55\u4e0b\u6765\uff0c\u6bd4\u5982\u56fe\u7247\u7684\u8de8\u57df\u95ee\u9898\uff0c\u6587\u5b57\u7684\u95ee\u9898\uff0c\u505a\u5b8c\u6ca1\u6709\u8bb0\u5f55\uff0c\u65e0\u8ff9\u53ef\u5bfb\uff0c\u4ee5\u81f3\u4e8e\u5f88\u96be\u5f00\u59cb\u3002\u6700\u8fd1\u91cd\u65b0\u56de\u987e\u4e86\u4e00\u4e0b\uff0c\u6574\u7406\u4e86\u4e00\u7bc7\u6587\u6863\uff0c\u6216\u6709\u758f\u6f0f\u548c\u4e0d\u51c6\u786e\u4e4b\u5904\uff0c\u6b22\u8fce\u4ea4\u6d41\u3002<\/p><\/blockquote>\n<h2>\u4e8c\u3001\u4e1a\u52a1\u5e94\u7528<\/h2>\n<h4>pc:<\/h4>\n<p>1.\u5206\u4eab\u6d77\u62a5<\/p>\n<h4>H5\u5e94\u7528:<\/h4>\n<p>1.\u5206\u4eab\u4f18\u60e0\u5238<br \/>\n2.\u5e74\u5ea6\u8d26\u5355<br \/>\n3.\u5206\u4eab\u6d77\u62a5<\/p>\n<h2>\u4e09\u3001\u5b9e\u73b0\u65b9\u5f0f\u53ca\u517c\u5bb9\u6027\u95ee\u9898<\/h2>\n<h4>\u7b2c\u4e09\u65b9\u5e93<\/h4>\n<h5>1. html2canvas<\/h5>\n<p>\u7248\u672c 1.0.0rc7<\/p>\n<p><a class=\"url\" href=\"https:\/\/github.com\/niklasvh\/h\" target=\"_blank\">https:\/\/github.com\/niklasvh\/h<\/a>&#8230;<\/p>\n<p>star:22k<\/p>\n<p>\u65f6\u95f4 2021-01-06<\/p>\n<p>\u9996\u9875\u6d4b\u8bd5demo\uff1a<a class=\"url\" href=\"https:\/\/html2canvas.hertzen.com\/\" target=\"_blank\">https:\/\/html2canvas.hertzen.com\/<\/a><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3243\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/20210425084503.png\" alt=\"20210425084503\" width=\"872\" height=\"353\" \/><\/p>\n<h5>\u517c\u5bb9\u6027\u6d4b\u8bd5<\/h5>\n<h5>\u5b89\u5353<\/h5>\n<ul>\n<li>\u2705 6.0 koobee<\/li>\n<li>\u2705 5.0.2 vovoY51A<\/li>\n<\/ul>\n<h5>\u5b89\u5353\u5fae\u4fe1\u7248\u672c-\u5185\u7f6e<\/h5>\n<ul>\n<li>\u2705 7.0.3<\/li>\n<li>\u2705 7.0.22<\/li>\n<\/ul>\n<h5>ios<\/h5>\n<ul>\n<li>\u2705 14.2<\/li>\n<li>\u2705 11.2.1<\/li>\n<\/ul>\n<h5>ios\u5fae\u4fe1\u5185\u7f6e<\/h5>\n<ul>\n<li>\u2705 7.0.20<\/li>\n<li>\u2705 7.0.1<\/li>\n<\/ul>\n<h5>\u4f18\u70b9\uff1a<\/h5>\n<p>\u517c\u5bb9\u6027\u66f4\u597d\uff0c\u5b98\u65b9\u63cf\u8ff0\u5982\u4e0b\uff1a<\/p>\n<pre><code>Browser compatibility\r\nThe library should work fine on the following browsers (with Promise polyfill):\r\n\r\nFirefox 3.5+\r\nGoogle Chrome\r\nOpera 12+\r\nIE9+\r\nSafari 6+\r\nAs each CSS property needs to be manually built to be supported, there are a number of properties that are not yet supported.\r\n<\/code><\/pre>\n<h5>\u7f3a\u70b9\uff1a<\/h5>\n<p>\u4e00\u4e9b\u5c5e\u6027\u4e0d\u652f\u6301\u8f6c\u5316\uff1a\u5982\u4e0d\u652f\u6301\u4f2a\u7c7b\uff0cborder\u4e0d\u652f\u6301dash\uff0c\u4e0d\u652f\u6301text-shadow\uff0c\uff08\u5373\u8fd8\u539f\u7a0b\u5ea6\u9700\u8981\u548c\u8bbe\u8ba1\u6c9f\u901a\uff0c\u6216\u8005\u8003\u8651\u91c7\u7528\u56fe\u7247\u7b49\u5f62\u5f0f\u53bb\u66ff\u6362\u663e\u793a\u5143\u7d20\uff09<\/p>\n<p>features\uff1a<a class=\"url\" href=\"https:\/\/html2canvas.hertzen.c\" target=\"_blank\">https:\/\/html2canvas.hertzen.c<\/a>&#8230;<\/p>\n<h5>\u5907\u6ce8<\/h5>\n<p>rc5\u51fa\u73b0\u8fc7ios\u751f\u6210\u4e0d\u4e86\u56fe\u7247\u7684\u95ee\u9898\uff0c\u8fd8\u539f\u5230rc4\u5c31\u53ef\u4ee5\u4e86<br \/>\n<a class=\"url\" href=\"https:\/\/github.com\/niklasvh\/h\" target=\"_blank\">https:\/\/github.com\/niklasvh\/h<\/a>&#8230;<\/p>\n<p>\u770b\u5230issue\u91cc\u6709\u51fa\u73b0ios\u67d0\u4e9b\u7248\u672c\u4e0b\u5fae\u4fe1\u5931\u8d25\u7684\u60c5\u51b5\uff0c\u6682\u6ca1\u6709\u590d\u73b0<\/p>\n<h5>2 dom-to-img<\/h5>\n<p>\u7248\u672c2.6.0<\/p>\n<p><a class=\"url\" href=\"https:\/\/github.com\/tsayen\/dom\" target=\"_blank\">https:\/\/github.com\/tsayen\/dom<\/a>&#8230;<\/p>\n<p>star:6.9k<\/p>\n<h5>\u4f18\u70b9<\/h5>\n<p>\u5143\u7d20\u9f50\u5168\uff0c\u8fd8\u539f\u5ea6\u9ad8<\/p>\n<h5>\u7f3a\u70b9<\/h5>\n<p>\u4e0d\u517c\u5bb9safari\uff0c\u6240\u4ee5\u5efa\u8bae\u53ea\u5728Chrome\u4e0b\u4f7f\u7528<\/p>\n<p>\u6ca1\u6709\u7ef4\u62a4\u66f4\u65b0\u4e86<\/p>\n<h5>\u517c\u5bb9\u6027\u95ee\u9898<\/h5>\n<p>1.\u4f5c\u8005\u660e\u786e\u8868\u793a\u4e0d\u652f\u6301safari\uff0c\u56e0\u4e3aforeignObject\u7684\u5b89\u5168\u6027\u95ee\u9898\uff08\u660e\u8bf4\u4e86\u4e0d\u652f\u6301\uff0c\u6211\u4ed4\u7ec6\u770b\u6587\u6863 =&gt; \u767d\u4f5c\u5de5 \uff09<\/p>\n<p>\u94fe\u63a5\uff1a<\/p>\n<ul>\n<li><a class=\"url\" href=\"https:\/\/github.com\/tsayen\/dom\" target=\"_blank\">https:\/\/github.com\/tsayen\/dom<\/a>&#8230;<\/li>\n<li><a class=\"url\" href=\"https:\/\/html.spec.whatwg.org\/\" target=\"_blank\">https:\/\/html.spec.whatwg.org\/<\/a>&#8230;<\/li>\n<li>SVG\u5728Web\u653b\u51fb\u4e2d\u7684\u5e94\u7528: <a class=\"url\" href=\"https:\/\/www.anquanke.com\/post\" target=\"_blank\">https:\/\/www.anquanke.com\/post<\/a>&#8230;<\/li>\n<\/ul>\n<p>2.iOS14.2\u4e0b\uff0c\u56fe\u7247\u4e22\u5931\u95ee\u9898<br \/>\n\u5176\u5b9e\u5728\u6d4b\u7684\u65f6\u5019\uff0c\u53d1\u73b0ios14.2\u4e0b\u751f\u6210\u56fe\u7247\u7b2c\u4e00\u6b21\u59cb\u7ec8\u4f1a\u51fa\u73b0\u56fe\u7247\u4e22\u5931\uff0c\u7b2c\u4e8c\u6b21\u6216\u7b2c\u4e09\u6b21\u6b63\u5e38<br \/>\n\u89e3\u51b3\u65b9\u6848\uff0c2\uff5e3\u6b21\u8c03\u7528\uff0c\u53d6\u6700\u540e\u4e00\u6b21\uff08\u770bissue\u91cc\u6709\u4e9b\u673a\u578b\u8fd8\u662f\u4e0d\u652f\u6301\u7684\uff09<\/p>\n<p>3.\u4f4e\u7aef\u5b89\u5353\u673a\u4e0a\u4f1a\u51fa\u73b0\u5931\u8d25\u60c5\u51b5\uff0c\u4e3b\u8981\u662f\u6587\u5b57\u7684\u95ee\u9898\uff08\u8fd9\u91cc\u662f\u6211\u5199\u8fc7\u7684\u65e7\u7684\u8bb0\u5f55\uff0c\u4e0d\u662f\u5f88\u786e\u5b9a\uff09<br \/>\n<a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/20210425083933.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3245\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/20210425083933.png\" alt=\"20210425083933\" width=\"1044\" height=\"400\" \/><\/a><\/p>\n<h5>\u5e94\u7528\u4e8ePc\u6216android<\/h5>\n<ol>\n<li>\n<pre><code>\u6e05\u6670\u5ea6\u95ee\u9898\uff1a\\(\u770b\u5230\u5f88\u591a\u4eba\u8bf4\u8981\u53bb\u6539\u6e90\u7801\uff0c\u5176\u5b9e\u4e0d\u7528\u7684\uff0c\u4f5c\u8005\u662f\u63d0\u4f9b\u4e86\u53c2\u6570\u4e86\\)\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<pre><code class=\"language-javascript\" lang=\"javascript\">\u901a\u8fc7scale\u653e\u5927\u8bbe\u5907\u7684DPR\u500d\u6570\r\nlet elm = document.getElementById('my-node')\r\nconst scale = window.devicePixelRatio\r\nthis.loader.open()\r\nawait this.$nextTick()\r\ndomtoimage\r\n    .toBlob(elm, {\r\n         quantity: 1,\r\n         width: elm.offsetWidth * scale, \/\/ \u753b\u5e03\u653e\u5927\r\n         height: elm.offsetHeight * scale,\r\n        style: {\r\n            transform: `scale(${scale})`, \/\/ \u5143\u7d20\u653e\u5927\r\n            transformOrigin: '0 0',\r\n        },\r\n    })\r\n    .then(this.upload) \/\/ \u5904\u7406\u7ed3\u679c\r\n    .catch(function (error) {\r\n        this.loader.close()\r\n        console.error('oops, something went wrong!', error)\r\n    })\r\n<\/code><\/pre>\n<h4>\u524d\u7aefcanvas\u7ed8\u5236<\/h4>\n<h5>0.canvas<\/h5>\n<pre><code class=\"language-javascript\" lang=\"javascript\">let canvasBox = document.createElement('canvas')\r\nlet ctx = canvasBox.getContext(\r\n                    '2d'\r\n                ) as CanvasRenderingContext2D\r\n<\/code><\/pre>\n<h5>1.img<\/h5>\n<pre><code class=\"language-javascript\" lang=\"javascript\">let bgImag = ''\r\nctx.drawImage(bgImg, 0, 0)\r\n<\/code><\/pre>\n<h5>1.2\u56fe\u7247\u8de8\u57df\u95ee\u9898<\/h5>\n<pre><code>\u89e3\u51b3\u529e\u6cd5 \uff1a\r\n1\uff09\u4f7f\u7528 crossOrigin \u5c5e\u6027\u3002\r\n\u89e3\u51b3canvas\u56fe\u7247getImageData,toDataURL\u8de8\u57df\u95ee\u9898\r\n2\uff09\u56fe\u7247\u672c\u8eab\u4e5f\u9700\u8981\u5141\u8bb8\u8de8\u57df\r\n3\uff09\u8bbe\u7f6e useCORS\uff1atrue\uff0c\u539f\u7406\u76f8\u540c\uff0c\u4f46\u4f7f\u7528\u4ee5\u4e0a\u8de8\u57df\u65b9\u6cd5\uff0c\u82e5\u540c\u65f6\u8bbe\u7f6e\u4e3a allowTaint\uff1atrue \uff0c\u4ecd\u7136\u4f1a\u8ba4\u4e3a\u753b\u5e03\u5df2\u88ab\u6c61\u67d3\u800c\u4e0d\u53ef\u7528\uff1b\r\n<\/code><\/pre>\n<h5>2.\u6587\u5b57<\/h5>\n<h5>2.2\u6587\u5b57\u6362\u884c<\/h5>\n<pre><code>\u6838\u5fc3\uff1a\u8ba1\u7b97\u6240\u6709\u6587\u5b57\uff0c\u6839\u636e\u6bcf\u884c\u53ef\u663e\u793a\u7684\u6700\u5927\u5bbd\u5ea6\uff0c\u6765\u62c6\u5206\u6210\u6bcf\u884c\u6e32\u67d3\r\n\u53c2\u8003\uff1ahttps:\/\/www.zhangxinxu.com\/wordpress\/2018\/02\/canvas-text-break-line-letter-spacing-vertical\/\r\n<\/code><\/pre>\n<h5>2.2\u5b57\u4f53\u7c7b\u578b<\/h5>\n<p>2.2.1.\u53ea\u91c7\u7528\u9ed8\u8ba4\u5b57\u4f53\u6216\u5c11\u91cf\u5b9a\u5236\u5b57\u4f53\uff08Fontmin\u83b7\u53d6\u7279\u5b9a\u5b57\u4f53\u7684\u5b57\u4f53\uff0c\u5199\u6b7b\u7684\u6570\u636e\uff0c\u5982\u679c\u6362\u884c\u9700\u8981\u8ba1\u7b97\u6362\u884c\u95ee\u9898-\u7a7a\u683c\u56de\u8f66\u7b49\u5947\u8469\u95ee\u9898\uff09- ==<strong>@font-face\uff0c\u8fd9\u6837\u4f7f\u7528\u662f\u6d89\u53ca\u7248\u6743\u95ee\u9898\u7684\uff0c\u786e\u4fdd\u4f60\u4eec\u6709\u8be5\u5b57\u4f53\u7684\u7248\u6743<\/strong>==<\/p>\n<pre><code class=\"language-css\" lang=\"css\">@font-face {\r\n    font-family: \"DIN Condensed\";\r\n    \/\/ prettier-ignore\r\n    src: url(\"~@\/assets\/fonts\/DIN-Condensed-Bold.woff\") format(\"woff\"), url(\"~@\/assets\/fonts\/DIN-Condensed-Bold.ttf\") format(\"ttf\");\r\n}\r\n\r\n@font-face {\r\n    font-family: \"PingFang SC Bold\";\r\n    \/\/ prettier-ignore\r\n    src: url(\"~@\/assets\/fonts\/PingFang-SC-Bold.ttf\") format(\"ttf\"), url(\"~@\/assets\/fonts\/PingFang-SC-Bold.woff\") format(\"woff\");\r\n}\r\nctx.fillText('20px PingFang SC Bold', x, y)\r\nctx.fillText('20px', x, y)\r\n<\/code><\/pre>\n<p>2.2.2\uff08\u4e00\u5b9a\u8981\u5b8c\u6574\u67d0\u79cd\u5b57\u4f53\u7684\u60c5\u51b5\u4e0b\uff1a\u52a8\u6001\u53d8\u5316\u7684\u6570\u636e\uff0c\u9700\u8981\u63a5\u53e3\u652f\u6301\uff09<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">svg to img\r\n\u76f4\u63a5domtoSvg\u4e5f\u6709\u5b89\u5353\u5931\u8d25\u7684\u95ee\u9898\r\nlet svg = \u63a5\u53e3\u83b7\u53d6svg\uff08\u53c2\u8003\u5e74\u5ea6\u8d26\u5355\uff09\r\nlet svgBase64: string =\r\n    'data:image\/svg+xml;base64,' +\r\n    window.btoa(\r\n        unescape(encodeURIComponent(svg))\r\n    )\r\n\r\nawait this.loadImg(svgBase64).then(\r\n    img =&gt; {\r\n        ctxC.drawImage(\r\n            img,\r\n            ~~(20 * this.scale),\r\n            ~~(186 * this.scale)\r\n        )\r\n    }\r\n)\r\n<\/code><\/pre>\n<h5>3.\u624b\u673a\u7aef\u6bd4\u4f8b\u8ba1\u7b97<\/h5>\n<pre><code class=\"language-javascript\" lang=\"javascript\">\/\/ \u5c3d\u91cf\u4f7f\u7528\u6574\u6570\r\n\r\n\/\/ devicePixelRatio\r\nprotected imgQuality = window.devicePixelRatio\r\n\r\n\/\/ \u548c\u8bbe\u8ba1\u7a3f\u7684\u6bd4\u4f8b \u8bbe\u8ba1\u7a3f\u5bbd\u5ea6\u662f640\r\nget scale() {\r\n    return (document.body.clientWidth * this.imgQuality) \/ 640\r\n}\r\n\r\n\/\/ \u753b\u5e03\u5bbd\u9ad8\uff0c\u907f\u514d\u751f\u6210\u7684\u56fe\u7247\u6a21\u7cca\u60c5\u51b5\u51fa\u73b0\r\ncanvasBox.width = Math.ceil(\r\n    document.body.clientWidth * this.imgQuality\r\n)\r\ncanvasBox.height = Math.ceil(980 * this.scale)\r\n\r\n\/\/ \u4e8c\u7ef4\u7801\u7684\u5bbd\u5ea6\r\nget qrCodeSize() {\r\n    return ~~(155 * this.scale) \/\/ rpx * scale\r\n}\r\n<\/code><\/pre>\n<h5>4.\u5e38\u89c1\u5143\u7d20\/\u7ebf\/\u5706\/\u5706\u89d2\u77e9\u5f62<\/h5>\n<pre><code class=\"language-javascript\" lang=\"javascript\">\/\/ \u753b\u5e03\u548c\u8bbe\u8ba1\u7a3f750\u7684\u6bd4\u4f8b\r\nscale =  (document.body.clientWidth * this.imgQuality) \/ 750\r\n\u7ebf\uff1a\r\n**\r\n * \u753b\u7ebf\r\n *\/\r\nexport function drawLine(\r\n    ctx: CanvasRenderingContext2D,\r\n    data: {\r\n        x: number\r\n        y: number\r\n        width: number\r\n        height: number\r\n        strokeStyle: string\r\n    },\r\n    scale: number\r\n) {\r\n    let x = data.x * scale\r\n    let y = data.y * scale\r\n    let dx = (data.x + data.width) * scale\r\n    let dy = data.y * scale\r\n\r\n    \/\/ \u5f00\u59cb\u4e00\u4e2a\u65b0\u7684\u7ed8\u5236\u8def\u5f84\r\n    ctx.beginPath()\r\n    \/\/ \u5b9a\u4e49\u76f4\u7ebf\u7684\u8d77\u70b9\u5750\u6807\u4e3a(10,10)\r\n    ctx.moveTo(x, y)\r\n    \/\/ \u5b9a\u4e49\u76f4\u7ebf\u7684\u7ec8\u70b9\u5750\u6807\u4e3a(50,10)\r\n    ctx.lineTo(dx, dy)\r\n    \/\/ \u989c\u8272\r\n    ctx.strokeStyle = data.strokeStyle\r\n    \/\/ \u6cbf\u7740\u5750\u6807\u70b9\u987a\u5e8f\u7684\u8def\u5f84\u7ed8\u5236\u76f4\u7ebf\r\n    ctx.stroke()\r\n    \/\/ \u5173\u95ed\u5f53\u524d\u7684\u7ed8\u5236\u8def\u5f84\r\n    ctx.closePath()\r\n}\r\n\r\n\u5706\uff1a\r\n\/**\r\n * \u753b\u5706\r\n *\/\r\nexport function drawCircle(\r\n    ctx: CanvasRenderingContext2D,\r\n    data: {\r\n        x: number \/\/ \u5706\u5fc3\r\n        y: number\r\n        size: number \/\/ \u534a\u5f84\r\n        fillStyle: string\r\n    },\r\n    scale: number\r\n) {\r\n    ctx.save()\r\n    ctx.beginPath()\r\n    ctx.arc(\r\n        ~~(data.x * scale),\r\n        ~~(data.y * scale),\r\n        ~~(data.size * scale),\r\n        0,\r\n        ~~(data.size * scale * Math.PI)\r\n    )\r\n    ctx.fillStyle = data.fillStyle\r\n    ctx.fill()\r\n    ctx.restore()\r\n}\r\n\r\n\u77e9\u5f62\uff1a\r\n\r\n\/**\r\n * \u753b\u5706\u89d2\u77e9\u5f62\r\n *\/\r\nexport function drawRoundRect(\r\n    ctx: CanvasRenderingContext2D,\r\n    data: {\r\n        x: number\r\n        y: number\r\n        width: number\r\n        height: number\r\n        radius: number\r\n        fillStyle: string\r\n    },\r\n    scale: number\r\n) {\r\n    let width = ~~(data.width * scale)\r\n    let height = ~~(data.height * scale)\r\n    let radius = ~~(data.radius * scale)\r\n    let fillStyle = data.fillStyle\r\n    ctx.save()\r\n    ctx.translate(~~(data.x * scale), ~~(data.y * scale))\r\n    ctx.beginPath()\r\n    \/\/ \u4ece\u53f3\u4e0b\u89d2\u987a\u65f6\u9488\u7ed8\u5236\uff0c\u5f27\u5ea6\u4ece0\u52301\/2PI\r\n    ctx.arc(width - radius, height - radius, radius, 0, Math.PI \/ 2)\r\n\r\n    \/\/ \u77e9\u5f62\u4e0b\u8fb9\u7ebf\r\n    ctx.lineTo(radius, height)\r\n\r\n    \/\/ \u5de6\u4e0b\u89d2\u5706\u5f27\uff0c\u5f27\u5ea6\u4ece1\/2PI\u5230PI\r\n    ctx.arc(radius, height - radius, radius, Math.PI \/ 2, Math.PI)\r\n\r\n    \/\/ \u77e9\u5f62\u5de6\u8fb9\u7ebf\r\n    ctx.lineTo(0, radius)\r\n\r\n    \/\/ \u5de6\u4e0a\u89d2\u5706\u5f27\uff0c\u5f27\u5ea6\u4ecePI\u52303\/2PI\r\n    ctx.arc(radius, radius, radius, Math.PI, (Math.PI * 3) \/ 2)\r\n\r\n    \/\/ \u4e0a\u8fb9\u7ebf\r\n    ctx.lineTo(width - radius, 0)\r\n\r\n    \/\/ \u53f3\u4e0a\u89d2\u5706\u5f27\r\n    ctx.arc(width - radius, radius, radius, (Math.PI * 3) \/ 2, Math.PI * 2)\r\n\r\n    \/\/ \u53f3\u8fb9\u7ebf\r\n    ctx.lineTo(width, height - radius)\r\n    ctx.closePath()\r\n    ctx.fillStyle = fillStyle\r\n    ctx.fill()\r\n    ctx.restore()\r\n}\r\n<\/code><\/pre>\n<h5>5.canvasBox.toBlob<\/h5>\n<pre><code class=\"language-javascript\" lang=\"javascript\">canvasBox.toBlob(async data =&gt; {\r\n    if (data) {\r\n        \/\/\u4e0a\u4f20\u52307niu\r\n        this.url = await uploadFile(data)\r\n    }\r\n})\r\n<\/code><\/pre>\n<h5>6.\u56fe\u7247\u4fdd\u5b58<\/h5>\n<h5>PC<\/h5>\n<pre><code class=\"language-javascript\" lang=\"javascript\">import { saveAs } from 'file-saver'\r\nsaveAs(blob, filename)\r\n<\/code><\/pre>\n<h5>H5<\/h5>\n<pre><code>\u957f\u6309\u4fdd\u5b58\r\n\u5305\u58f3\u7684H5\u662f\u53ef\u4ee5\u5b9e\u73b0\u76f4\u63a5\u4e0b\u8f7d\u7684\uff0c\u4f46\u4e3a\u4e86\u4ea4\u4e92\u4e86\u4e00\u81f4\u6027\uff0c\u8fd8\u662f\u7528\u4e86\u957f\u6309\r\n<\/code><\/pre>\n<h4>\u63a5\u53e3\u751f\u6210<\/h4>\n<p>\u63a5\u53e3\u751f\u6210\uff0c\u4f20\u5165\u5143\u7d20\u548c\u4f4d\u7f6e\u7b49\u4fe1\u606f\uff0c\u63a5\u53e3\u76f4\u63a5\u751f\u6210\u8fd4\u56de\u56fe\u7247\u3002\u9700\u8981\u540e\u7aef\u5b9e\u73b0\u3002\uff08\u5177\u4f53\u7684\u6027\u80fd\u548c\u4f7f\u7528\u6848\u4f8b\uff0c\u6b22\u8fce\u8ba8\u8bba\u3002\uff09<\/p>\n<h5>\u4f18\u70b9<\/h5>\n<p>\u4e0d\u9700\u8981\u8003\u8651\u517c\u5bb9\u6027\u7b49\u95ee\u9898<\/p>\n<h5>\u7f3a\u70b9<\/h5>\n<p>\u4e0d\u652f\u6301\u5b57\u6570\u6216\u5b57\u4f53\u7c7b\u578b\u8fc7\u591a\uff0c\u670d\u52a1\u5668\u538b\u529b\u8f83\u5927\uff08\u770b\u5177\u4f53\u5b9e\u73b0\u65b9\u6848\uff09\uff0c\u5143\u7d20\u8d8a\u591a\uff0c\u63a5\u53e3\u8d8a\u6162<\/p>\n<p>\u8fd9\u4e2a\u65b9\u6848\u5176\u5b9e\u4e5f\u662f\u7528\u540e\u7aef\u7684\u903b\u8f91\u5b9e\u73b0\u4e86\u7ed8\u5236\u5143\u7d20\uff0c\u8f93\u51fa\u56fe\u7247\uff08\u8fc7\u7a0b\u4e2d\u9047\u5230\u7684\u95ee\u9898\uff1a\u5982\u6362\u884c\u60c5\u51b5\u4e0b\u9700\u8981\u8ba1\u7b97\u5b57\u4f53\u9ad8\u5ea6\uff08\u540c\u4e00\u5b57\u4f53\u7684\u4e2d\u82f1\u6587\u5bbd\u5ea6\u4e0d\u540c\uff09\u548c\u540e\u7eed\u5143\u7d20\u7684\u76f8\u5bf9\u4f4d\u7f6e\u53d1\u751f\u53d8\u5316\uff09<\/p>\n<h2>\u56db\u3001\u56fe\u7247\u8de8\u57df<\/h2>\n<p>\u5982\u679c\u5b58\u5728\u8de8\u57df\u56fe\u7247\u65e0\u6cd5\u4e0b\u8f7d\uff0c\u4ed4\u7ec6\u9605\u8bfb\u4ee5\u4e0b\u6587\u5b57\uff1a<br \/>\n\u6765\u6e90\uff1a<a class=\"url\" href=\"https:\/\/segmentfault.com\/q\/10\" target=\"_blank\">https:\/\/segmentfault.com\/q\/10<\/a>&#8230;<br \/>\n<a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/20210425084029.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3246\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2021\/04\/20210425084029.png\" alt=\"20210425084029\" width=\"1075\" height=\"654\" \/><\/a><\/p>\n<h2>\u4e94\u3001\u603b\u7ed3<\/h2>\n<p>\u65e0\u7279\u6b8a\u60c5\u51b5\u65f6\uff0cpc\u4e0b\u4f7f\u7528dom-to-image\u5373\u53ef\u3002<br \/>\n\u81f3\u4e8eh5\uff0c\u56de\u987e\u4e86\u4e00\u4e0b\u81ea\u5df1\u7ed8\u5236\u6d77\u62a5\u7684\u5b9e\u73b0\u5386\u7a0b\uff1a<br \/>\n1.\u7b2c\u4e09\u65b9\u5e93(\u517c\u5bb9\u6027\u95ee\u9898\uff0c\u592a\u4e45\u8fdc\u4ee5\u81f3\u4e8e\u4e0d\u8bb0\u5f97\u53d1\u751f\u4e86\u4ec0\u4e48\uff0c\u53ea\u8bb0\u5f97\u8fd9\u4e2a\u65b9\u6848\u88ab\u9a73\u56de\u4e86)<br \/>\n2.\u63a5\u53e3\u7ed8\u5236\uff08\u670d\u52a1\u5668\u8fc7\u8f7d\u6027\u80fd\u95ee\u9898\uff0c\u901f\u5ea6\u8fc7\u6162\uff09<br \/>\n3.\u524d\u7aefcanvas\u7ed8\u5236\uff08+\u90e8\u5206\u5143\u7d20\u63a5\u53e3\u7ed8\u5236\u597d\u8fd4\u56de\u56fe\u7247\u6216svg\uff0c\u57fa\u672c\u6ca1\u4ec0\u4e48\u517c\u5bb9\u95ee\u9898\uff09\uff08\u901f\u5ea6\u8fc7\u6162\uff09<br \/>\n4.\u7b2c\u4e09\u65b9\u5e93\uff08html2canvas\uff0c\u6d4b\u8bd5\u4e86\u4e00\u4e9b\u7248\u672c\u73af\u5883\u7684\u517c\u5bb9\u6027\uff0c\u4f46\u9879\u76ee\u6682\u672a\u4e0a\u7ebf\uff0c\u9700\u8981\u89c2\u5bdf\uff09<br \/>\n\u76ee\u524d\u6700\u4f18\u89e3\u770b\u8d77\u6765\u662fhtml2canvas\uff0c\u4f46\u662f\u6709\u4e9b\u6548\u679c\u65e0\u6cd5\u5b9e\u73b0\uff0c\u9700\u8981\u5728\u8fd8\u539f\u5ea6\u548c\u6027\u80fd\u4e0a\u505a\u53d6\u820d\u3002<\/p>\n<h2>\u516d\u3001\u66f4\u597d\u7684\u65b9\u6848\uff1f<\/h2>\n<p>\u4e00\u4e9b\u5e38\u7528\u7684app\u7684\u6d77\u62a5\u751f\u6210\u662f\u66f4\u5feb\u7684\uff0c\u4f53\u9a8c\u4e5f\u66f4\u597d\uff0c\u4e0d\u77e5\u9053\u662f\u4e0d\u662f\u5b58\u5728\u66f4\u597d\u7684\u89e3\u51b3\u65b9\u6848\uff1f\u8fd8\u662fh5\u7684\u9650\u5236\uff1f<\/p>\n<h2>\u4e03\u3001\u53c2\u8003<\/h2>\n<ol>\n<li>\u3010JS\u3011\u8282\u70b9\u622a\u56fe\u7684\u6700\u7ec8\u89e3\u51b3\u65b9\u6848dom-to-image\u4e0ehtml2canvas\uff1a<a class=\"url\" href=\"https:\/\/blog.csdn.net\/Mcky_Lo\" target=\"_blank\">https:\/\/blog.csdn.net\/Mcky_Lo<\/a>&#8230;<\/li>\n<li>\u79fb\u52a8\u7aefH5\u9875\u9762\u622a\u56fe\uff1a<a class=\"url\" href=\"https:\/\/cloud.tencent.com\/dev\" target=\"_blank\">https:\/\/cloud.tencent.com\/dev<\/a>&#8230;<\/li>\n<li>\u628aDOM\u8282\u70b9\u751f\u6210base64\u56fe\u7247\uff1a<a class=\"url\" href=\"https:\/\/www.jianshu.com\/p\/c5c\" target=\"_blank\">https:\/\/www.jianshu.com\/p\/c5c<\/a>&#8230;<\/li>\n<li>\u66f4\u4f18\u96c5\u5730\u57fa\u4e8e canvas \u5728\u524d\u7aef\u753b\u6d77\u62a5\uff1a<a class=\"url\" href=\"https:\/\/juejin.cn\/post\/684490\" target=\"_blank\">https:\/\/juejin.cn\/post\/684490<\/a>&#8230;<\/li>\n<li>canvas\u6587\u672c\u7ed8\u5236\u81ea\u52a8\u6362\u884c\u3001\u5b57\u95f4\u8ddd\u3001\u7ad6\u6392\u7b49\u5b9e\u73b0 <a class=\"url\" href=\"https:\/\/www.zhangxinxu.com\/wo\" target=\"_blank\">https:\/\/www.zhangxinxu.com\/wo<\/a>&#8230;<\/li>\n<li>\u56fe\u7247\u8de8\u57df\u95ee\u9898\uff1a<a class=\"url\" href=\"https:\/\/segmentfault.com\/q\/1010000008648867\" target=\"_blank\">https:\/\/segmentfault.com\/q\/1010000008648867<\/a><\/li>\n<li><a class=\"url\" href=\"https:\/\/mp.weixin.qq.com\/s\/UB9cCPPf7k_vVvlrcbka-g\" target=\"_blank\">https:\/\/mp.weixin.qq.com\/s\/UB9cCPPf7k_vVvlrcbka-g<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u80cc\u666f \u5de5\u4f5c\u4e2d\u505a\u4e86\u5f88\u591a\u751f\u6210\u6d77\u62a5\u7684\u529f\u80fd\uff0c\u4e0d\u540c\u9700\u6c42\uff0c\u4e0d\u540c\u573a\u666f\uff0c\u4f7f\u7528\u4e86\u51e0\u79cd\u65b9\u6848\uff0c\u5404\u6709\u4f18\u52a3\u3002\u4e00\u76f4\u60f3\u8981\u6574\u7406\u4e00\u4e0b\uff0c\u4f46\u8fd9\u4e2a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[109,105],"tags":[156],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3241"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3241"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3241\/revisions"}],"predecessor-version":[{"id":3247,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3241\/revisions\/3247"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}