เมื่อเร็ว ๆ นี้ฉันต้องเปิดวิธีการแบ่งปัน WeChat ของแอพไปยัง WebView ซึ่งเกี่ยวข้องกับภาพที่ใช้ร่วมกัน หากคุณเชื่อมต่อผ่านการถ่ายโอนรูปภาพคุณจะได้รับไฟล์รูปภาพอีกครั้งในพื้นหลังซึ่งจะส่งผลกระทบต่อความเร็ว ฉันเลือก WebView เพื่อส่งผ่านภาพไปยังแอปพลิเคชันท้องถิ่นในการเข้ารหัส Base64-bit นี่คือรหัสอ้างอิงการใช้งาน:
<! doctype html> <html> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"> <title> ภาพเป็น base64-jsfiddle demo โดย handtrix </title> src = '// code.jquery.com/jquery-2.0.2.js'> </script> <link rel = "stylesheet" type = "text/css" href = "/css/result-light.css" rel = "ภายนอก url ('// netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css'); ร่างกาย {padding: 20px; } </style> <script type = 'text/javascript'> // <! [cdata [$ (หน้าต่าง) .load (function () {/** * convertimgtobase64 * @param {string} url * @param {function} callback * @param {string} convertimgtobase64 ('http://goo.gl/aoxhal', ฟังก์ชั่น (base64img) {console.log ('ภาพ:', base64img);}) */ฟังก์ชั่น convertimgtobase64 (url, callback, outputformat) canvas.getContext ('2d'); 'png'); ConvertimGTOBASE64 (ImageUrl, function (base64img) {$ ('. output') .find ('textarea') .val (base64img) .end () .find (') .attr (' '' '' '' '' ' base64img); - Event.preventDefault (); - }); //]]> </script> </head> <body> <h2> อินพุต </h2> <form id = "img2b64"> <อินพุต type = "url" name = "url" placeholder = "แทรก image-url" value = "http://upload.wikimedia.org/wikipedia/commons/4/4a/logo_2013_google.png" จำเป็น> <pan> <อินพุตประเภท = "ส่ง" <a> </a> <br> <br> <img> <br> </div> </body> </html>PS: นี่คือเครื่องมือสำหรับการเข้ารหัสภาพออนไลน์ Base64 สำหรับการอ้างอิงของคุณ:
การแปลงภาพเป็น Base64 การเข้ารหัสเครื่องมือออนไลน์ : http://tools.vevb.com/transcoding/img2base64