{"id":182,"date":"2025-11-25T09:05:50","date_gmt":"2025-11-25T01:05:50","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=182"},"modified":"2025-11-25T09:05:50","modified_gmt":"2025-11-25T01:05:50","slug":"html5%e5%ae%9e%e7%8e%b0plus-io%e8%bf%9b%e8%a1%8c%e6%8b%8d%e7%85%a7%e5%92%8c%e5%9b%be%e7%89%87%e7%ad%89%e8%8e%b7%e5%8f%96","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/11\/25\/html5%e5%ae%9e%e7%8e%b0plus-io%e8%bf%9b%e8%a1%8c%e6%8b%8d%e7%85%a7%e5%92%8c%e5%9b%be%e7%89%87%e7%ad%89%e8%8e%b7%e5%8f%96\/","title":{"rendered":"html5+\u5b9e\u73b0plus.io\u8fdb\u884c\u62cd\u7167\u548c\u56fe\u7247\u7b49\u83b7\u53d6"},"content":{"rendered":"\n<p>\u5728 HTML5+ (DCloud\/HBuilder) \u5f00\u53d1\u4e2d\uff0c\u8981\u5b9e\u73b0\u62cd\u7167\u3001\u4ece\u76f8\u518c\u9009\u56fe\uff0c\u5e76\u6700\u7ec8\u8bfb\u53d6\u56fe\u7247\u6587\u4ef6\uff0c\u6838\u5fc3\u662f\u7ed3\u5408\u4f7f\u7528 <code>plus.camera<\/code>\uff08\u6444\u50cf\u5934\uff09\u3001<code>plus.gallery<\/code>\uff08\u76f8\u518c\uff09\u548c <code>plus.io<\/code>\uff08\u6587\u4ef6\u7cfb\u7edf\uff09\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u6700\u5927\u7684\u75db\u70b9\u901a\u5e38\u662f<strong>\u8def\u5f84\u8f6c\u6362<\/strong>\uff1a\u62cd\u7167\u8fd4\u56de\u7684\u901a\u5e38\u662f\u76f8\u5bf9\u8def\u5f84\uff08\u5982 <code>_doc\/xxx.jpg<\/code>\uff09\uff0c\u76f4\u63a5\u653e\u5165 <code>&lt;img&gt;<\/code> \u6807\u7b7e\u53ef\u80fd\u65e0\u6cd5\u663e\u793a\uff0c\u5fc5\u987b\u901a\u8fc7 <code>plus.io<\/code> \u8f6c\u6362\u4e3a\u672c\u5730\u7edd\u5bf9\u8def\u5f84 (<code>file:\/\/\/...<\/code>)\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u5b8c\u6574\u7684\u5b9e\u73b0\u65b9\u6848\u548c\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6838\u5fc3\u903b\u8f91\u6d41\u7a0b<\/h3>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>\u62cd\u7167 (<code>plus.camera<\/code>)<\/strong>: \u8c03\u7528\u6444\u50cf\u5934 -> \u83b7\u53d6\u56fe\u7247\u8def\u5f84\u3002<\/li>\n\n\n\n<li><strong>\u76f8\u518c (<code>plus.gallery<\/code>)<\/strong>: \u6253\u5f00\u76f8\u518c -> \u9009\u62e9\u56fe\u7247 -> \u83b7\u53d6\u56fe\u7247\u8def\u5f84\u3002<\/li>\n\n\n\n<li><strong>\u8def\u5f84\u5904\u7406 (<code>plus.io<\/code>)<\/strong>: \u5c06\u4e0a\u8ff0\u4e24\u79cd\u65b9\u5f0f\u83b7\u53d6\u7684\u8def\u5f84\uff0c\u901a\u8fc7 <code>resolveLocalFileSystemURL<\/code> \u8f6c\u6362\u4e3a\u53ef\u7528\u7684 <code>entry<\/code> \u5bf9\u8c61\uff0c\u518d\u901a\u8fc7 <code>.toLocalURL()<\/code> \u83b7\u53d6 <code>&lt;img src><\/code> \u53ef\u8bc6\u522b\u7684\u5730\u5740\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b8c\u6574\u4ee3\u7801\u793a\u4f8b<\/h3>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u76f4\u63a5\u5c06\u6b64\u4ee3\u7801\u7247\u6bb5\u653e\u5165\u4f60\u7684 js \u6587\u4ef6\u6216 <code>&lt;script&gt;<\/code> \u6807\u7b7e\u4e2d\u3002<\/p>\n\n\n\n<p>JavaScript<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ \u5b9a\u4e49\u5168\u5c40\u53d8\u91cf\u65b9\u4fbf\u8c03\u8bd5\nvar cmr = null;\n\n\/\/ \u76d1\u542c plusready \u4e8b\u4ef6\uff0c\u786e\u4fdd HTML5+ \u73af\u5883\u51c6\u5907\u5c31\u7eea\ndocument.addEventListener(&quot;plusready&quot;, function() {\n    \/\/ \u83b7\u53d6\u6444\u50cf\u5934\u7ba1\u7406\u5bf9\u8c61\n    cmr = plus.camera.getCamera();\n}, false);\n\n\/**\n * 1. \u62cd\u7167\u51fd\u6570\n *\/\nfunction captureImage() {\n    if (!cmr) {\n        alert(&quot;\u6444\u50cf\u5934\u672a\u5c31\u7eea&quot;);\n        return;\n    }\n\n    var res = cmr.supportedImageResolutions&#x5B;0]; \/\/ \u83b7\u53d6\u652f\u6301\u7684\u5206\u8fa8\u7387\n    var fmt = cmr.supportedImageFormats&#x5B;0];     \/\/ \u83b7\u53d6\u652f\u6301\u7684\u683c\u5f0f\n\n    console.log(&quot;\u5f00\u59cb\u62cd\u7167...&quot;);\n    \n    cmr.captureImage(function(path) {\n        \/\/ \u6210\u529f\u56de\u8c03\uff1apath \u662f\u62cd\u7167\u540e\u7684\u6587\u4ef6\u8def\u5f84\uff08\u901a\u5e38\u662f\u76f8\u5bf9\u8def\u5f84\uff0c\u5982 &quot;_doc\/camera\/123.jpg&quot;\uff09\n        console.log(&quot;\u62cd\u7167\u6210\u529f\uff0c\u8def\u5f84\uff1a&quot; + path);\n        \n        \/\/ \u3010\u5173\u952e\u6b65\u9aa4\u3011\u5c06\u8def\u5f84\u8f6c\u6362\u4e3a\u672c\u5730\u9884\u89c8\u5730\u5740\n        resolveFile(path);\n        \n    }, function(error) {\n        \/\/ \u5931\u8d25\u56de\u8c03\n        console.log(&quot;\u62cd\u7167\u5931\u8d25: &quot; + error.message);\n        if(error.code !== 11) { \/\/ 11 \u662f\u7528\u6237\u53d6\u6d88\u64cd\u4f5c\uff0c\u4e0d\u9700\u8981\u5f39\u7a97\n             alert(&quot;\u62cd\u7167\u5931\u8d25: &quot; + error.message);\n        }\n    }, {\n        resolution: res,\n        format: fmt\n    });\n}\n\n\/**\n * 2. \u4ece\u76f8\u518c\u9009\u62e9\u51fd\u6570\n *\/\nfunction pickImageFromGallery() {\n    console.log(&quot;\u6253\u5f00\u76f8\u518c...&quot;);\n    \n    plus.gallery.pick(function(path) {\n        \/\/ \u6210\u529f\u56de\u8c03\uff1apath \u662f\u9009\u62e9\u56fe\u7247\u7684\u8def\u5f84\n        console.log(&quot;\u9009\u62e9\u6210\u529f\uff0c\u8def\u5f84\uff1a&quot; + path);\n        \n        \/\/ \u76f8\u518c\u8fd4\u56de\u7684\u8def\u5f84\u901a\u5e38\u5df2\u7ecf\u662f\u7edd\u5bf9\u8def\u5f84\uff0c\u4f46\u4e3a\u4e86\u7edf\u4e00\u5904\u7406\uff0c\n        \/\/ \u4f9d\u7136\u5efa\u8bae\u8d70\u4e00\u904d resolveFile\uff0c\u6216\u8005\u76f4\u63a5\u663e\u793a\n        showImage(path); \n        \n    }, function(error) {\n        \/\/ \u5931\u8d25\u56de\u8c03\n        console.log(&quot;\u9009\u62e9\u5931\u8d25: &quot; + error.message);\n    }, {\n        filter: &quot;image&quot;, \/\/ \u53ea\u9009\u62e9\u56fe\u7247\n        multiple: false, \/\/ \u5355\u9009\n        system: false    \/\/ \u5c3d\u91cf\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u907f\u514d\u90e8\u5206\u5b89\u5353\u673a\u578b\u517c\u5bb9\u95ee\u9898\n    });\n}\n\n\/**\n * 3. \u3010\u6838\u5fc3\u3011\u5229\u7528 plus.io \u5c06\u8def\u5f84\u8f6c\u6362\u4e3a\u53ef\u663e\u793a\u7684 URL\n * @param {String} path - \u539f\u59cb\u8def\u5f84 (\u5982 _doc\/...)\n *\/\nfunction resolveFile(path) {\n    \/\/ \u901a\u8fc7URL\u53c2\u6570\u83b7\u53d6\u76ee\u5f55\u5bf9\u8c61\u6216\u6587\u4ef6\u5bf9\u8c61\n    plus.io.resolveLocalFileSystemURL(path, function(entry) {\n        \n        \/\/ entry \u662f\u4e00\u4e2a\u6587\u4ef6\u5b9e\u4f53\u5bf9\u8c61\n        \/\/ entry.toLocalURL() \u83b7\u53d6\u672c\u5730\u7edd\u5bf9\u8def\u5f84 (file:\/\/\/storage\/...)\n        \/\/ \u8fd9\u79cd\u8def\u5f84\u53ef\u4ee5\u76f4\u63a5\u8d4b\u503c\u7ed9 img src\n        var localUrl = entry.toLocalURL(); \n        \n        console.log(&quot;\u672c\u5730\u7edd\u5bf9\u8def\u5f84\uff1a&quot; + localUrl);\n        \n        \/\/ \u663e\u793a\u56fe\u7247\n        showImage(localUrl);\n        \n        \/\/ \u5982\u679c\u4f60\u9700\u8981\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u4e0a\u4f20\uff08\u4f8b\u5982\u8f6c Base64 \u6216\u8bfb\u53d6 File \u5bf9\u8c61\uff09\n        \/\/ readFileEntry(entry); \n\n    }, function(e) {\n        console.log(&quot;\u8bfb\u53d6\u6587\u4ef6\u9519\u8bef\uff1a&quot; + e.message);\n    });\n}\n\n\/**\n * \u8f85\u52a9\uff1a\u5728\u9875\u9762\u663e\u793a\u56fe\u7247\n *\/\nfunction showImage(url) {\n    \/\/ \u5047\u8bbe\u9875\u9762\u4e0a\u6709\u4e00\u4e2a img \u6807\u7b7e id=&quot;myImage&quot;\n    var img = document.getElementById(&quot;myImage&quot;);\n    if (img) {\n        img.src = url;\n    } else {\n        console.log(&quot;\u672a\u627e\u5230\u56fe\u7247\u5143\u7d20\uff0c\u56fe\u7247\u5730\u5740\u4e3a\uff1a&quot; + url);\n    }\n}\n\n\/**\n * \u8fdb\u9636\uff1a\u5982\u679c\u9700\u8981\u8bfb\u53d6\u6587\u4ef6\u6570\u636e\u7528\u4e8e\u4e0a\u4f20 (\u8bfb\u53d6\u4e3a File \u5bf9\u8c61)\n *\/\nfunction readFileEntry(fileEntry) {\n    fileEntry.file(function(file) {\n        \/\/ file \u5bf9\u8c61\u7c7b\u4f3c\u4e8e Web API \u7684 File\uff0c\u5305\u542b name, size, type \u7b49\n        console.log(&quot;\u6587\u4ef6\u540d\uff1a&quot; + file.name);\n        console.log(&quot;\u6587\u4ef6\u5927\u5c0f\uff1a&quot; + file.size);\n        \n        \/\/ \u914d\u5408 FileReader \u8bfb\u53d6\u5185\u5bb9\n        var fileReader = new plus.io.FileReader();\n        fileReader.readAsDataURL(file); \/\/ \u6bd4\u5982\u8f6c base64\n        fileReader.onloadend = function(evt) {\n            console.log(&quot;Base64\u6570\u636e\u524d\u7f00\uff1a&quot; + evt.target.result.substring(0, 50));\n            \/\/ \u8fd9\u91cc\u53ef\u4ee5\u5c06 evt.target.result \u53d1\u9001\u7ed9\u670d\u52a1\u5668\n        }\n    });\n}\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ee3\u7801\u5173\u952e\u70b9\u89e3\u6790<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. <code>plus.io.resolveLocalFileSystemURL(path, successCB, errorCB)<\/code><\/h4>\n\n\n\n<p>\u8fd9\u662f\u6700\u91cd\u8981\u7684 API\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e3a\u4ec0\u4e48\u9700\u8981\u5b83\uff1f<\/strong> \u62cd\u7167\u8fd4\u56de\u7684\u8def\u5f84\u901a\u5e38\u662f <code>_doc\/<\/code> \u5f00\u5934\u7684\u76f8\u5bf9\u8def\u5f84\u3002\u539f\u751f\u5c42\u80fd\u8bc6\u522b\uff0c\u4f46 Webview \u4e2d\u7684 HTML <code>&lt;img><\/code> \u6807\u7b7e\u6709\u65f6\u65e0\u6cd5\u76f4\u63a5\u8bc6\u522b\u8fd9\u79cd\u865a\u62df\u8def\u5f84\u3002<\/li>\n\n\n\n<li><strong>\u5b83\u7684\u4f5c\u7528\uff1a<\/strong> \u5b83\u5c06\u8def\u5f84\u89e3\u6790\u4e3a <code>FileEntry<\/code> \u5bf9\u8c61\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2. <code>entry.toLocalURL()<\/code><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u83b7\u5f97 <code>FileEntry<\/code> \u540e\uff0c\u8c03\u7528\u6b64\u65b9\u6cd5\u4f1a\u8fd4\u56de\u4e00\u4e2a\u4ee5 <code>file:\/\/<\/code> \u5f00\u5934\u7684\u672c\u5730\u7edd\u5bf9\u8def\u5f84\u3002\u8fd9\u662f\u6700\u5b89\u5168\u3001\u517c\u5bb9\u6027\u6700\u597d\u7684\u8def\u5f84\u683c\u5f0f\uff0c\u53ef\u4ee5\u76f4\u63a5\u8d4b\u503c\u7ed9 <code>&lt;img src=\"...\"><\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">3. \u6743\u9650\u914d\u7f6e (<code>manifest.json<\/code>)<\/h4>\n\n\n\n<p>\u5728\u6253\u5305 App \u65f6\uff0c\u8bf7\u786e\u4fdd\u5728 <code>manifest.json<\/code> \u4e2d\u52fe\u9009\u4e86\u76f8\u5e94\u7684\u6a21\u5757\u6743\u9650\uff0c\u5426\u5219\u4ee3\u7801\u4f1a\u62a5\u9519\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Camera<\/strong>: \u6444\u50cf\u5934<\/li>\n\n\n\n<li><strong>Gallery<\/strong>: \u76f8\u518c<\/li>\n\n\n\n<li><strong>File (IO)<\/strong>: \u6587\u4ef6\u7cfb\u7edf (\u7528\u4e8e <code>plus.io<\/code>)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u5e38\u89c1\u5751\u4e0e\u89e3\u51b3\u65b9\u6848<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u56fe\u7247\u65cb\u8f6c\u95ee\u9898<\/strong>\uff1a\u90e8\u5206 Android \u624b\u673a\u62cd\u7167\u540e\uff0c\u56fe\u7247\u867d\u7136\u663e\u793a\u6b63\u5e38\uff0c\u4f46\u4e0a\u4f20\u6216\u67d0\u4e9b\u7279\u5b9a\u573a\u666f\u4e0b\u4f1a\u65cb\u8f6c 90 \u5ea6\u3002\u5982\u679c\u9047\u5230\u6b64\u95ee\u9898\uff0c\u9700\u8981\u5728\u663e\u793a\u524d\u5229\u7528 Canvas \u6216\u540e\u7aef\u8fdb\u884c\u4fee\u6b63\u3002<\/li>\n\n\n\n<li><strong>\u8def\u5f84\u4e2d\u7684 <code>file:\/\/<\/code><\/strong>\uff1a\u5728\u67d0\u4e9b\u8f83\u65b0\u7684 Android \u7248\u672c\uff08Android 10+\uff09\u6216 iOS Webview \u4e2d\uff0c\u76f4\u63a5\u4f7f\u7528 <code>file:\/\/<\/code> \u534f\u8bae\u52a0\u8f7d\u56fe\u7247\u53ef\u80fd\u4f1a\u53d7\u5230\u5b89\u5168\u7b56\u7565\u9650\u5236\uff08Webview \u65e0\u6cd5\u52a0\u8f7d\u672c\u5730\u6587\u4ef6\uff09\u3002\u5982\u679c\u9047\u5230\u56fe\u7247\u52a0\u8f7d\u4e0d\u51fa\u6765\uff1a\n<ul class=\"wp-block-list\">\n<li>\u53ef\u4ee5\u4f7f\u7528 <code>entry.toRemoteURL()<\/code> \u8bd5\u8bd5\uff08\u867d\u7136\u540d\u5b57\u53eb Remote\uff0c\u4f46\u5728\u67d0\u4e9b\u73af\u5883\u7528\u4e8e\u672c\u5730\u6620\u5c04\uff09\u3002<\/li>\n\n\n\n<li>\u6216\u8005\u5728 <code>manifest.json<\/code> \u4e2d\u914d\u7f6e <code>plus<\/code> -> <code>distribute<\/code> -> <code>plugins<\/code> \u76f8\u5173\u7684 Webview \u8bbe\u7f6e\u3002<\/li>\n\n\n\n<li>\u6700\u901a\u7528\u7684\u73b0\u4ee3\u505a\u6cd5\u662f\u4f7f\u7528 <code>plus.io.convertLocalFileSystemURL(path)<\/code> \u8f6c\u6362\u8def\u5f84\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>\u4e0b\u4e00\u6b65\u5efa\u8bae\uff1a<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u9700\u8981\u5b9e\u73b0\u56fe\u7247\u4e0a\u4f20\uff08\u5c06\u83b7\u53d6\u5230\u7684\u56fe\u7247\u53d1\u7ed9\u540e\u7aef\uff09\uff0c\u4f60\u9700\u8981\u7528\u5230 plus.uploader \u6a21\u5757\u6216\u8005\u5c06\u56fe\u7247\u8f6c\u4e3a Base64\u3002\u662f\u5426\u9700\u8981\u6211\u63d0\u4f9b\u201c\u56fe\u7247\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u201d\u7684\u76f8\u5173\u4ee3\u7801\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 HTML5+ (DCloud\/HBuilder) \u5f00\u53d1\u4e2d\uff0c\u8981\u5b9e\u73b0\u62cd\u7167\u3001\u4ece\u76f8\u518c&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/11\/25\/html5%e5%ae%9e%e7%8e%b0plus-io%e8%bf%9b%e8%a1%8c%e6%8b%8d%e7%85%a7%e5%92%8c%e5%9b%be%e7%89%87%e7%ad%89%e8%8e%b7%e5%8f%96\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-182","post","type-post","status-publish","format-standard","hentry","category-html5"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=182"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/182\/revisions"}],"predecessor-version":[{"id":183,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/182\/revisions\/183"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}