في الآونة الأخيرة ، أحتاج إلى فتح طريقة مشاركة WeChat للتطبيق على WebView ، والتي تتضمن الصور المشتركة. إذا قمت بالاتصال من خلال نقل الصور ، فسوف تحصل على ملف الصورة مرة أخرى في الخلفية ، مما سيؤثر على السرعة. لقد اخترت WebView لتمرير الصورة إلى التطبيق المحلي في ترميز BASE64 بت. هنا هو رمز مرجع التنفيذ:
<! doctype html> <html> <head> <meta http-equiv = "content-type" content = "text/html ؛ charset = utf-8"> <title> صورة إلى base64-JSFiddle Demo by Handtrix </title> <trict typ src = '// code.jquery.com/jquery-2.0.2.js'> </script> <link rel = "stylesheet" type = "text/css" href = "/css/result light.css url ('// netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css') ؛ الجسم {padding: 20px ؛ } </style> <script type = 'text/javaScript'> // <! convertimgtobase64 ('http://goo.gl/aoxhal' ، function (base64Img) {console.log ('Image:' ، base64Img) ؛}) canvas.getContex (2d ') ؛ "Image/PNG ') ؛ convertimgtobase64 (imageUrl ، function (base64Img) {$ ('. output') .find ('textarea') .val (base64Img) .end () .find ('a') .Attr ('href' ، base64Img) .text (base64im). }) ؛ Event.PreventDefault () ؛ }) ؛ }). value = "http://upload.wikimedia.org/wikipedia/commons/4/4a/logo_2013_google.png" المطلوبة> <span> <pectara = "إرسال"> </span> </part> <a> </a> <br> <br> <img> <br> </viv> </body> </html>ملاحظة: فيما يلي أداة لترميز تحويل الصور عبر الإنترنت 64 للرجوع إليها:
تحويل الصورة إلى Base64 ترميز أداة عبر الإنترنت : http://tools.vevb.com/transcoding/img2base64