{"id":6661,"date":"2017-12-24T16:04:04","date_gmt":"2017-12-24T08:04:04","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=6661"},"modified":"2019-11-25T17:39:48","modified_gmt":"2019-11-25T09:39:48","slug":"js-css-encrypt-to-image","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2017\/12\/js-css-encrypt-to-image\/","title":{"rendered":"\u778e\u6298\u817e\uff1a\u628aJS,CSS\u4efb\u610f\u6587\u672c\u6587\u4ef6\u52a0\u5bc6\u6210\u4e00\u5f20\u56fe\u7247"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=6661\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=6661<\/a><br \/>\n\u672c\u6587\u53ef\u5168\u6587\u8f6c\u8f7d\uff0c\u4f46\u9700\u5f97\u5230\u539f\u4f5c\u8005\u4e66\u9762\u8bb8\u53ef\uff0c\u540c\u65f6\u4fdd\u7559\u539f\u4f5c\u8005\u548c\u51fa\u5904\uff0c\u6458\u8981\u5f15\u6d41\u5219\u968f\u610f\u3002<\/p>\n<h3>\u4e00\u3001\u8fd9\u662f\u4e00\u5f20\u5305\u542b\u7279\u6b8a\u4fe1\u606f\u7684\u52a0\u5bc6\u56fe\u7247<\/h3>\n<p>64\u50cf\u7d20*64\u50cf\u7d20\u539f\u59cb\u52a0\u5bc6\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.zhangxinxu.com\/study\/201712\/file2img\/img\/colorful-min.png\" width=\"64\" height=\"64\" alt=\"\u52a0\u5bc6\u56fe\u7247\" class=\"alignnone\" \/><\/p>\n<p>\u653e\u59275\u500d\u5448\u73b0\u540e\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201712\/2017-12-24_135045.png\" width=\"320\" height=\"320\" alt=\"\u653e\u5927\u5448\u73b0\u7684\u52a0\u5bc6\u56fe\u7247\" class=\"alignnone\" \/><\/p>\n<p>\u8fd9\u5f2064*64\u89c1\u65b9\u7684\u56fe\u7247\u5b9e\u9645\u4e0a\u5305\u542b\u4e86\u4e00\u6bb54K\u5927\u5c0f\u7684JavaScript\u811a\u672c\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u76f8\u4fe1\u5982\u679c\u4e0d\u77e5\u9053\u8fd9\u5f20\u56fe\u7247\u7684\u52a0\u5bc6\u7b97\u6cd5\uff0c\u5c31\u7b97\u662f\u7231\u56e0\u65af\u5766\u4e5f\u5f88\u96be\u77ed\u65f6\u95f4\u7834\u89e3\u4e4b\u3002<\/p>\n<h3>\u4e8c\u3001JavaScript\u4ee3\u7801\u7684\u56fe\u7247\u52a0\u5bc6\u4e0e\u89e3\u5bc6<\/h3>\n<p>\u52a0\u89e3\u5bc6\u7684\u539f\u7406\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li><strong>\u52a0\u5bc6\uff1a<\/strong>\u83b7\u53d6\u6587\u672c\u5b57\u7b26\u7684Unicode\u7f16\u7801\uff0c\u8303\u56f4\u662f 0 &#8211; 65535 \u4e4b\u95f4\u7684\u6574\u6570\u3002\u7136\u540e\u628a\u8fd9\u4e2a\u6574\u6570\u8f6c\u5316\u6210RGB\u8272\u503c\uff0c\u6bcf\u4e00\u4e2a\u5b57\u7b26\u5bf9\u5e94\u4e00\u4e2a\u50cf\u7d20\u503c\u989c\u8272\uff0c\u7136\u540e\u7ed8\u5236\u6210\u56fe\u7247\u3002<\/li>\n<li><strong>\u89e3\u5bc6\uff1a<\/strong>\u8bfb\u53d6\u56fe\u7247\u7684\u50cf\u7d20\u4fe1\u606f\uff0c\u8f6c\u5316\u6210\u5bf9\u5e94\u7684Unicode\u7f16\u7801\uff0c\u518d\u8f6c\u6362\u6210\u5bf9\u5e94\u5b57\u7b26\u3002<\/li>\n<\/ul>\n<h4>\u52a0\u89e3\u5bc6\u7684\u5a92\u4ecbcanvas<\/h4>\n<p>\u52a0\u5bc6\u7684\u56fe\u7247\u751f\u6210\uff0c\u89e3\u5bc6\u7684\u56fe\u7247\u4fe1\u606f\u8bfb\u53d6\uff0c\u90fd\u662f\u501f\u52a9<code>canvas<\/code>\u5b9e\u73b0\u7684\u3002<\/p>\n<p><code>canvas<\/code> API\u4e2d\u7684<code>putImageData<\/code>\u53ef\u4ee5\u7528\u6765\u751f\u6210\u56fe\u7247\uff1b<code>canvas<\/code> API\u4e2d\u7684<code>getImageData<\/code>\u53ef\u4ee5\u7528\u6765\u8bfb\u53d6\u56fe\u7247\u4e2d\u7684\u50cf\u7d20\u4fe1\u606f\u3002<\/p>\n<p>\u5bf9\u4e8e\u901a\u8fc7web\u751f\u6210\u7684\u6570\u636e\uff0c\u6211\u4eec\u5904\u7406\u76f8\u5bf9\u7b80\u5355\u4e00\u4e9b\uff0c\u56e0\u4e3a\u90fd\u5728\u540c\u4e00\u4e2aweb\u5e73\u53f0\u4e0a\u3002<\/p>\n<p>\u4f8b\u5982\u6211\u4eec\u53d1\u8868\u4e86\u4e00\u7bc7\u9700\u8981\u4ed8\u8d39\u9605\u8bfb\u7684\u6587\u7ae0\uff0c\u53ef\u4ee5\u8fd9\u4e48\u5904\u7406\uff1a<\/p>\n<ol>\n<li>\u5c06\u6587\u7ae0\u6587\u672c\u8f6c\u6362\u6210RGB\u989c\u8272\u4fe1\u606f\u7ed8\u5236\u5728canvas\u753b\u5e03\u4e0a\uff1b<\/li>\n<li>\u901a\u8fc7<code>canvas<\/code>\u7684<code>toDataURL()<\/code>\u65b9\u6cd5\uff0c\u5c06\u753b\u5e03\u4fe1\u606f\u8f6c\u4e3a<code>base64<\/code>\u683c\u5f0f\uff0c\u53d1\u9001\u7ed9\u540e\u7aef\uff0c\u540e\u7aef\u4ee5\u56fe\u7247\u683c\u5f0f\u8fdb\u884c\u4fe1\u606f\u63a5\u6536\uff08\u6216\u76f4\u63a5base64\u5730\u5740\u5165\u5e93\u2014\u2014\u5927\u5c0f\u90fd\u5dee\u4e0d\u591a\uff09\uff1b<\/li>\n<li>\u5f53\u9700\u8981\u5448\u73b0\u6587\u7ae0\u7684\u65f6\u5019\uff0c\u901a\u8fc7\u8bfb\u53d6\u8fd9\u5f20\u56fe\u7247\u4fe1\u606f\u8fdb\u884c\u89e3\u5bc6\uff0c\u5f97\u5230\u6587\u7ae0\u5185\u5bb9\u3002\u7136\u540e\u518d\u4ee5\u753b\u5e03\u7684\u5f62\u5f0f\u663e\u793a\u6587\u7ae0\u5185\u5bb9\uff0c\u8fd9\u6837\u9875\u9762\u6e90\u4ee3\u7801\u548c\u5b9e\u65f6DOM\u90fd\u6ca1\u6709\u6587\u7ae0\u6587\u5b57\u4fe1\u606f\u3002\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u76d7\u7248\u7684\u95e8\u69db\u3002<\/li>\n<\/ol>\n<hr>\n<p>\u5982\u679c\u662f\u672c\u5730\u5f00\u53d1\u7684\u6e90\u4ee3\u7801\u60f3\u8981\u52a0\u5bc6\u5462\uff1f<\/p>\n<p>\u5219\u9700\u8981\u501f\u52a9\u672c\u5730\u5de5\u5177\u5bf9\u8fd9\u4e9b\u6587\u4ef6\u8fdb\u884c\u56fe\u7247\u683c\u5f0f\u8f6c\u6362\uff0c\u5bf9\u4e8e\u524d\u7aef\u5f00\u53d1\u540c\u5b66\u800c\u8a00\uff0c\u53ef\u4ee5\u81ea\u5df1\u5199\u4e00\u4e2anode.js\u5c0f\u5de5\u5177\u3002<\/p>\n<p>\u4e0b\u9762\u8fd9\u6bb5node.js\u4ee3\u7801\u5c31\u662f\u6211\u81ea\u5df1\u5199\u81ea\u5df1\u7528\u7684\uff0c\u5927\u5bb6\u6709\u5174\u8da3\u53ef\u4ee5\u4f5c\u4e3a\u53c2\u8003\uff1a<\/p>\n<pre>const { createCanvas, loadImage } = require('canvas');\r\nconst fs = require('fs');\r\nconst file2Img = function (filename) {\r\n    fs.readFile(filename, {\r\n        encoding: 'utf8'\r\n    }, function (err, data) {\r\n        let length = data.length;\r\n        let size = Math.ceil(Math.sqrt(length));\r\n        <span style=\"color:green;\">\/\/ \u7ed8\u5236canvas<\/span>\r\n        const canvas = createCanvas(size, size);\r\n        const ctx = canvas.getContext('2d');\r\n        <span style=\"color:green;\">\/\/ \u83b7\u53d6\u900f\u660e\u50cf\u7d20\u6570\u636e<\/span>\r\n        var imgData = ctx.getImageData(0, 0, size, size);\r\n        <span style=\"color:green;\">\/\/ \u900f\u660e\u50cf\u7d20\u6570\u636e\u66ff\u6362\u4e3a\u5b9e\u8272\u6570\u636e<\/span>\r\n        var index = 0;\r\n        for (var start=0; start&lt;size*size; start++) {\r\n            let charCode = data.charCodeAt(start);\r\n            if (Number.isNaN(charCode) == false) {\r\n                let hex = (charCode + '').padStart(6, '0');\r\n                for (var i=0; i&lt;6; i+=2) {\r\n                    imgData.data[index++] = parseInt('0x' + hex.slice(i, i + 2));   \r\n                }\r\n                <span style=\"color:green;\">\/\/ \u900f\u660e\u5ea6<\/span>\r\n                imgData.data[index++] = 255;\r\n            }\r\n        }\r\n        <span style=\"color:green;\">\/\/ \u4f7f\u7528\u65b0\u989c\u8272\u4fe1\u606f\u7ed8\u5236<\/span>\r\n        ctx.putImageData(imgData, 0, 0);\r\n\r\n        <span style=\"color:green;\">\/\/ \u4fdd\u5b58\u7684PNG\u6587\u4ef6\u540d<\/span>\r\n        var imgFilename = filename.split('.')[0] + '.png';\r\n        let stream = canvas.pngStream();        \r\n        <span style=\"color:green;\">\/\/ \u8f93\u51faPNG\u6d41<\/span>\r\n        let out = fs.createWriteStream(__dirname + '\/' + imgFilename);\r\n        stream.on('data', function(chunk) {\r\n          out.write(chunk);\r\n        });\r\n        stream.on('end', function(){\r\n          console.log('The '+ imgFilename +' stream ended');\r\n        });\r\n    });\r\n};<\/pre>\n<p>\u4f7f\u7528\u793a\u610f\uff0c\u547d\u540d\u4e00\u4e2afile2img.js\u6587\u4ef6\uff0c\u590d\u5236\u5e76\u7c98\u8d34\u4e0a\u9762JS\u4ee3\u7801\uff0c\u4ee3\u7801\u6700\u540e\u52a0\u4e0a\u4e0b\u9762\u4e00\u53e5\uff08js\u6587\u4ef6\u540d\u6362\u6210\u4f60\u5e0c\u671b\u8f6c\u6362\u7684\uff09\uff1a<\/p>\n<pre>file2Img('colorful-min.js');<\/pre>\n<p>\u7136\u540e\u6267\u884c\uff1a<\/p>\n<pre>node file2img<\/pre>\n<p>\u6b64\u65f6\uff0c\u5c31\u4f1a\u628a<a href=\"https:\/\/www.zhangxinxu.com\/study\/201712\/colorful-min.js\" rel=\"noopener\" target=\"_blank\">colorful-min.js<\/a>\u53d8\u6210<a href=\"https:\/\/www.zhangxinxu.com\/study\/201712\/file2img\/img\/colorful-min.png\" rel=\"noopener\" target=\"_blank\">colorful-min.png<\/a>\u56fe\u7247\u4e86\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201712\/2017-12-24_155926.png\" width=\"418\" height=\"80\" alt=\"\u56fe\u7247\u8f6c\u6362\u6210\u529f\u63d0\u793a\u622a\u56fe\" class=\"alignnone\" \/><\/p>\n<p><strong>\u672c\u5730\u5b9e\u73b0\u9ebb\u70e6\u4e4b\u5904<\/strong><br \/>\n\u770b\u4ee3\u7801\u91cf\uff0c\u4f3c\u4e4e\u89c9\u5f97\u672c\u5730\u6587\u4ef6\u8f6c\u56fe\u7247\u4e5f\u662f\u6d12\u6d12\u6c34\u7684\u7a0b\u5ea6\u3002<\/p>\n<p>\u4e8b\u975e\u7ecf\u8fc7\u4e0d\u77e5\u96be\uff0c\u672c\u5730\u6587\u4ef6\u8f6c\u56fe\u7247\uff0c\u9ebb\u70e6\u7684\u5176\u5b9e\u5e76\u4e0d\u662f\u4ee3\u7801\u5b9e\u73b0\u672c\u8eab\uff0c\u800c\u662f<code>node-canvas<\/code>\u6a21\u5757\u7684\u5b89\u88c5\uff08node-canvas\u9879\u76ee\u5730\u5740<a href=\"https:\/\/github.com\/Automattic\/node-canvas\" rel=\"nofollow\" target=\"_blank\">\u89c1\u8fd9\u91cc<\/a>\uff09\uff0c\u5c24\u5176\u5728<a href=\"https:\/\/github.com\/Automattic\/node-canvas\/wiki\/Installation---Windows\" rel=\"noopener\" target=\"_blank\">windows\u7cfb\u7edf\u4e0b\u7684\u5b89\u88c5<\/a>\uff0c\u6211\u770b\u7f51\u4e0a\u8fd8\u6709\u4eba\u6298\u817e\u4e86\u4e00\u6574\u5929\u624d\u5f04\u597d\u7684\u3002<\/p>\n<p>\u6211\u81ea\u5df1\u6298\u817e\u4e86\u597d\u51e0\u4e2a\u5c0f\u65f6\uff0c\u5b8c\u5168\u6309\u7167\u5b98\u65b9\u7684\u6b65\u9aa4\uff0c\u4e00\u4e2a\u4e2a\u7684\u5b89\u88c5\uff0c\u751a\u81f3\u4e3a\u4e86\u5b89\u88c5node-gyp\uff0c\u8fd8\u4e0b\u8f7d\u4e86\u5360\u7528\u4e863.29G\u7684Microsoft Visual C++ Build Tools\uff0c\u7ed3\u679c\u8fd8\u662f\u72d7\u5c4e\u3002<\/p>\n<p>\u4ec0\u4e48binding.gyp not found\uff0cc2373 __pfnDliNotifyHook2\u4e4b\u7c7b\u9519\u8bef\u3002<\/p>\n<p>\u6211\u8ddf\u5927\u5bb6\u8bb2\uff0c\u5b98\u65b9\u7684\u5b89\u88c5\u6559\u7a0b\uff0c\u5f88\u4e0d\u9760\u8c31\uff0c\u6f0f\u4e86\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u4e1c\u897f\u3002<\/p>\n<p>\u7b2c1\u6b65\u5e76\u4e0d\u662f\u5b89\u88c5node-gyp\uff0c\u800c\u662f\u5347\u7ea7Node.js\u5230\u6700\u65b0\u7248\u3002<\/p>\n<p>\u6211\u6298\u817e\u8fd9\u4e48\u4e45\uff0c\u5c31\u662f\u56e0\u4e3aNode.js\u8fd8\u662f\u8001\u7248\u672c\u7684\u539f\u56e0\uff0c <img decoding=\"async\" src=\"https:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/193.gif\" align=\"absmiddle\">\u3002<\/p>\n<p>\u7136\u540e\uff0c\u6211\u4f7f\u7528\u7684\u662f2.0\u7684\u7528\u6cd5\uff0c\u9ed8\u8ba4\u5b89\u88c5\u8fd8\u662f1.x\u7248\u672c\uff0c\u56e0\u6b64\uff0ccanvas\u5305\u5b89\u88c5\u65f6\u5019\uff0c\u8981\u8d70\u4e0b\u9762\uff1a<\/p>\n<pre>npm install canvas@next<\/pre>\n<h3>\u4e09\u3001\u89e3\u5bc6\u56fe\u7247\u5e76\u6267\u884c\u5b9e\u9645\u6848\u4f8b<\/h3>\n<p>\u4e0b\u9762\u8fd9\u6bb5JS\u53ef\u4ee5\u5bf9\u56fe\u7247\u8fdb\u884c\u89e3\u5bc6\u5e76\u76f4\u63a5\u6267\u884c\u5176\u5bf9\u5e94\u7684JavaScript\u811a\u672c\uff1a<\/p>\n<pre>var jsParseImg=function(l,g){var e=document.createElement(\"img\"),f=document.createElement(\"canvas\");e.onload=function(){f.width=this.width;f.height=this.height;var a=f.getContext(\"2d\");a.drawImage(this,0,0,this.width,this.height);for(var a=a.getImageData(0,0,this.width,this.height),e=a.data.length,h=[],b=0;b&lt;e;b+=4){var k=a.data[b].toString(16),c=a.data[b+1].toString(16),d=a.data[b+2].toString(16);a.data[b+2].toString(16);1==c.length&amp;&amp;(c=\"0\"+c);1==d.length&amp;&amp;(d=\"0\"+d);0!=Number(k+c+d)&amp;&amp;h.push(String.fromCharCode(Number(k+\r\nc+d)))}window.eval(h.join(\"\"));g&amp;&amp;g()};e.src=l};<\/pre>\n<p>\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>jsParseImg(imgurl, callback);<\/pre>\n<p>\u5176\u4e2d\uff0c<code>imgurl<\/code>\u53ea\u56fe\u7247\u7684URL\u5730\u5740\uff0c\u53ef\u4ee5\u662f\u666e\u901a\u534f\u8bae\u5730\u5740\uff0c\u4e5f\u53ef\u4ee5\u662fbase64\u5730\u5740\uff0c\u751a\u81f3\u662fBlob\u5730\u5740\uff1b<code>callback<\/code>\u4e3a\u89e3\u5bc6\u5e76\u89e3\u6790\u6210\u529f\u540e\u7684\u56de\u8c03\u3002<\/p>\n<p>\u773c\u89c1\u4e3a\u5b9e\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/201712\/js-parse-by-img.html\" rel=\"noopener\" target=\"_blank\">JS\u89e3\u6790\u89e3\u5bc6\u56fe\u7247\u5e76\u6267\u884cdemo<\/a><\/p>\n<p>\u5728<a href=\"https:\/\/www.zhangxinxu.com\/study\/201712\/iphonex-colorful-gradient-background.html\" rel=\"noopener\" target=\"_blank\">\u539fdemo\u9875\u9762<\/a>\u4e2d\uff0c\u70ab\u5f69\u80cc\u666f\u7684<code>colorfulBackground()<\/code>\u65b9\u6cd5\u662f\u5728<code>colorful-min.js<\/code>\u4e2d\u58f0\u660e\u7684\uff1b\u4f46\u662f\uff0c\u5728\u8fd9\u91cc\uff0c\u6709\u7684\u4ec5\u4ec5\u662f\u4e00\u4e2a<code>colorful-min.png<\/code>\u56fe\u7247\u8bf7\u6c42\u3002<\/p>\n<p>\u4f46\uff0c\u8fd9\u5e76\u4e0d\u59a8\u788d\u6211\u4eec\u6267\u884c\uff1a<\/p>\n<pre>jsParseImg('colorful-min.png', function () {\r\n    colorfulBackground({\r\n      container: document.getElementById('container'),\r\n      animation: false,\r\n      size: [400, 800]\r\n    });    \r\n});<\/pre>\n<p>\u6765\u5b9e\u73b0\u6211\u4eec\u60f3\u8981\u7684\u6548\u679c\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201712\/2017-12-24_150610.jpg\" width=\"234\" height=\"419\" alt=\"\u89e3\u5bc6\u56fe\u7247\u811a\u672c\u4fe1\u606f\u540e\u7684\u9875\u9762\u6548\u679c\" class=\"alignnone\" \/><\/p>\n<p>\u60f3\u5fc5\u90a3\u4e9b\u559c\u6b22\u6252\u4ee3\u7801\u7684\u4f38\u624b\u515a\uff0c\u770b\u4e86\u8fd9\u4e2a\u9875\u9762\u4e4b\u540e\uff0c\u4e00\u5b9a\u662f\u4e00\u8138\u61f5\u903c\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201712\/2017-12-24_151519.jpg\" width=\"280\" height=\"215\" alt=\"\u4e01\u5b81\u4e00\u8138\u61f5\u903c\" class=\"alignnone\" \/><\/p>\n<h3>\u56db\u3001\u7ed3\u675f\u8bed<\/h3>\n<p>\u6709\u5c0f\u4f19\u4f34\u53ef\u80fd\u4f1a\u62c5\u5fc3\uff0c\u52a0\u5bc6\u548c\u89e3\u5bc6\u7684\u4e1c\u897f\u5440\uff0c\u6700\u5b9d\u8d35\u7684\u5c31\u662f\u7b97\u6cd5\u4e86\uff0c\u4f60\u8fd9\u91cc\u57fa\u672c\u4e0a\u539f\u5c01\u4e0d\u52a8\u5c31\u66b4\u9732\u4e86\uff0c\u90a3\u57fa\u672c\u4e0a\u5c31\u6ca1\u5565\u7528\u4e86\u5440\u3002<\/p>\n<p>\u8fd9\u4e2a\u5176\u5b9e\u5927\u53ef\u4e0d\u5fc5\u62c5\u5fc3\u3002<\/p>\n<p>\u672c\u6587\u6240\u5c55\u793a\u7684\u989c\u8272\u5904\u7406\u53ea\u662f\u629b\u7816\u5f15\u7389\uff0c\u5c5e\u4e8e\u6700\u57fa\u672c\u6700\u7b80\u5355\u7684\uff0c\u4ece\u5934\u5f80\u540e\u7ebf\u6027\u7684\u989c\u8272\u7ed8\u5236\u3002<\/p>\n<p>\u5982\u679c\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u5e94\u7528\uff0c\u80af\u5b9a\u5c31\u4e0d\u4f1a\u60f3\u8fd9\u4e48\u7b80\u5355\u7684\u7b56\u7565\u4e86\u3002<\/p>\n<p>\u989c\u8272\u4fe1\u606f\u7684\u8d77\u70b9\u53ef\u4ee5\u4ece\u4e2d\u95f4\uff0c\u5706\u73af\u7684\u5f62\u5f0f\uff1b\u6216\u8005\u9010\u884c\u7ed8\u5236\u7684\u65b9\u5f0f\u3002<\/p>\n<p>\u6216\u8005\u66f4\u8fd1\u4e00\u6b65\uff0c\u6bcf\u4e00\u4e2a\u50cf\u7d20\u70b9\u85cf\u66f4\u591a\u7684\u4fe1\u606f\u3002\u56e0\u4e3a\u5b57\u7b26\u6700\u5927Unicode\u7f16\u7801\u662f65535\uff0c\u4f46\u662f\u4e00\u4e2a\u50cf\u7d20\u70b9RGBA\u6240\u80fd\u5305\u542b\u7684\u6570\u503c\u8303\u56f4\u4fe1\u606f\u662f256^4\uff0c\u4e5f\u5c31\u662f4294967296\uff0c\u5b8c\u5168\u4e0d\u662f\u4e00\u4e2a\u6570\u91cf\u7ea7\u7684\u3002\u5982\u679c\u91c7\u7528\u50cf\u7d20\u901a\u9053\u7ec4\u5408\u65b9\u5f0f\uff0c\u4e00\u4e2a\u50cf\u7d20\u70b9\u85cf2\u4e2a\u5b57\u7b26\u4fe1\u606f\uff0c\u662f\u5b8c\u5168\u53ef\u884c\u7684\u3002\u4e00\u4e2a\u50cf\u7d20\u901a\u9053\u8303\u56f4<code>0~255<\/code>\uff0c\u5176\u4e2d\u4e24\u4e2a\u7ec4\u5408\uff0c\u5219\u8303\u56f4\u5927\u5c0f256*256\u4e3a65536\uff0c\u6392\u9664\u6389\u8ba4\u4e3a\u662f\u65e0\u6548\u50cf\u7d20\u4fe1\u606f\u7684<code>0,0<\/code>\u7ec4\u5408\u6b63\u597d\u6db5\u76d665535\u3002<\/p>\n<p>\u6069\uff0c\u6709\u65f6\u95f4\u53ef\u4ee5\u518d\u8bd5\u8bd5\u3002<\/p>\n<p>\u8fd9\u6837\uff0c\u56fe\u7247\u7684\u5c3a\u5bf8\u53ef\u4ee5\u8fdb\u4e00\u6b65\u7f29\u5c0f\u3002<\/p>\n<p>\u672c\u6587\u5c55\u793a\u7684JS\u548c\u751f\u6210\u56fe\u7247\u5c3a\u5bf8\u5bf9\u6bd4\u4e3a\uff1a3.94K VS 5.33K\u3002\u9759\u6001\u8d44\u6e90\u6210\u672c\u662f\u6709\u6240\u589e\u52a0\u7684\uff0c\u5982\u4f55\u6743\u8861\uff0c\u8fd8\u8981\u770b\u5927\u5bb6\u81ea\u5df1\u3002<\/p>\n<hr>\n<p>\u5728\u524d\u7aef\u9886\u57df\uff0c\u662f\u6ca1\u6709\u767e\u5206\u4e4b\u767e\u7684\u52a0\u5bc6\u7684\uff0c\u53ea\u8981\u82b1\u8db3\u591f\u591a\u7684\u65f6\u95f4\u548c\u8010\u5fc3\uff0c\u603b\u4f1a\u7aa5\u63a2\u5230\u5230\u95e8\u8def\u7684\u3002\u800c\u4e14\u5bf9\u524d\u7aef\u6280\u672f\u8fd9\u79cd\u4e1c\u897f\uff0c\u90fd\u662f\u5f00\u653e\u7684\uff0c\u5c24\u5176web\u8fd9\u79cd\u9879\u76ee\uff0c\u4f60\u8bf4\u4f60JS\u4ee3\u7801\u9576\u4e86\u91d1\u9576\u4e86\u94bb\uff0c\u975e\u52a0\u5bc6\u4e0d\u53ef\uff0c\u60f3\u5fc5\u591a\u534a\u4f1a\u4e00\u7b11\u800c\u8fc7\u5427\u3002\u6240\u4ee5\uff0c\u5e73\u5e38\u7684\u538b\u7f29\u6df7\u6dc6\u5df2\u7ecf\u8db3\u591f\u4e86\u3002<\/p>\n<p>\u6240\u4ee5\u6807\u9898\u624d\u6709\u201c\u778e\u6298\u817e\u201d\u5b57\u6837\u3002\u81ea\u5df1\u73a9\u4e00\u73a9\u8bd5\u9a8c\u8bd5\u9a8c\uff0c\u5b9e\u9645\u4e0a\u5b9e\u9645\u5f00\u53d1\u7684\u4f30\u8ba1\u5f88\u5c11\u4f7f\u7528\u3002\u4f46\u662f\u7528\u7684\u5c11\uff0c\u5e76\u4e0d\u4e00\u5b9a\u6ca1\u6709\u4ef7\u503c\uff0c\u8bf4\u4e0d\u5b9a\u9047\u5230\u7279\u6b8a\u9879\u76ee\u7279\u6b8a\u573a\u666f\uff0c\u5c31\u80fd\u9ad8\u5149\u4e00\u628a\u3002<\/p>\n<p>\u611f\u8c22\u9605\u8bfb\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/201611\/14.png\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=6661\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=6661<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5468\u672b\u5728\u5bb6\u5c31\u662f\u5e94\u8be5\u653e\u677e\u7684\uff0c\u6211\u7684\u653e\u677e\u624b\u6bb5\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u5b66\u4e60\u524d\u7aef\u77e5\u8bc6\uff0c\u5199\u5199\u6587\u7ae0\uff0c\u62bd\u4e2a\u65f6\u95f4\u53bb\u9493\u9c7c\uff0c\u5b8c\u7f8e\u3002<\/p>\n<p>\u672c\u6587\u5185\u5bb9\u5c31\u662f\u4e00\u4e2a\u4e34\u65f6\u8d77\u610f\u7684\u6298\u817e\uff0c\u4e00\u4e2a\u5bf9JS\uff0cCSS\u7b49\u6587\u672c\u6587\u4ef6\u52a0\u5bc6\u4e3a\u56fe\u7247\u7684\u60f3\u6cd5\u3002\u4ecb\u7ecd\u4e86web\u4fe1\u606f\u8f6c\u56fe\u7247\u4ee5\u53ca\u672c\u5730\u6587\u4ef6\u5982\u4f55\u8f6c\u56fe\u7247\uff0c\u4ee5\u53ca\u5982\u4f55\u89e3\u5bc6\u7b49\u3002<\/p>\n<p>\u5e0c\u671b\u672c\u6587\u7684\u5185\u5bb9\u5bf9\u60a8\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[180],"tags":[53,888,1206,497,1130,1204,732,1205],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/6661"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=6661"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/6661\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=6661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=6661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=6661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}