从Android Bitmap

时间:2018-04-19 15:49:48

标签: java android html bitmap base64

我试图通过将Android应用程序中的图像转换为Base64来在PHP应用程序上显示Base64图像。它无法在我的浏览器上显示,但它在Android应用程序中很好。

我的Java代码

imgChild.buildDrawingCache();
Bitmap bmap = imgChild.getDrawingCache();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteFormat = stream.toByteArray();
String imgString = Base64.encodeToString(byteFormat, Base64.NO_WRAP);

这是从上面的代码

获得的Base64字符串
  

iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAYAAAB5fY51AAAAAXNSR0IArs4c6QAA       ABxpRE9UAAAAAgAAAAAAAACWAAAAKAAAAJYAAACWAAAH8srfvnsAAAe SURBVHgB       7NlhkqM2FEXhWUt ZGHZ / x4mIYl6GJD0hNvt9rU / qlKAnp5ww9GZW5Uff / 7x10 //       eQcYwEACAz8SfqTfaDNhAAMbA4QlYUrYGIhhgLDAGgOrlCVlERZhERYGYhggLLDG       wCphSViERViEhYEYBggLrDGwSlgSFmERFmFhIIYBwgJrDKwSloRFWIRFWBiIYYCw       wBoDq4QlYREWYREWBmIYICywxsAqYUlYhEVYhIWBGAYIC6wxsEpYEhZhERZhYSCG       AcICawysEpaERViERVgYiGGAsMAaA6uEJWERFmERFgZiGCAssMbAKmFJWIRFWISF       gRgGCAusMbBKWBIWYREWYWEghgHCAmsMrBKWhEVYhEVYGIhhgLDAGgOrhCVhERZh       ERYGYhggLLDGwCphSViERViEhYEYBggLrDGwSlgSFmERFmFhIIYBwgJrDKwSloRF       WIRFWBiIYYCwwBoDq4QlYREWYREWBmIYICywxsAqYUlYhEVYhIWBGAYIC6wxsEpY       EhZhERZhYSCGAcICawysEpaERViERVgYiGGAsMAaA6uEJWERFmERFgZiGCAssMbA       KmFJWIRFWISFgRgGCAusMbBKWBIWYREWYWEghgHCAmsMrBKWhEVYhEVYGIhhgLDA       GgOrhCVhERZhERYGYhggLLDGwCphSViERViEhYEYBggLrDGwSlgSFmERFmFhIIYB       wgJrDKwSloRFWIRFWBiIYYCwwBoDq4QlYREWYREWBmIYICywxsAqYUlYhEVYhIWB       GAYIC6wxsEpYEhZhERZhYSCGAcICawysEpaERViERVgYiGGAsMAaA6uEJWERFmER       FgZiGCAssMbAKmFJWIRFWISFgRgGCAusMbBKWBIWYREWYWEghgHCAmsMrBKWhEVY       hEVYGIhhgLDAGgOrhCVhERZhERYGYhggLLDGwCphSViERViEhYEYBggLrDGwSlgS       FmERFmFhIIYBwgJrDKwSloRFWIRFWBiIYYCwwBoDq4QlYREWYREWBmIYICywxsAq       YUlYhEVYhIWBGAYIC6wxsEpYEhZhERZhYSCGAcICawysEpaERViERVgYiGGAsMAa       A6uEJWERFmERFgZiGCAssMbAKmFJWIRFWISFgRgGCOuFYf154biaXqqlr65nvvS0       wgBhEdaHe1aAaXM mgYXbZ4zEd2TAcIirA / lXAHro2lwcWUtc0ltlQHCIqzflLMK       zm9NnZvVdcwjqysMEBZhnXSzAtCp6TCwsoY5ZHWVAcIirINqfi79H6NT02HgKojm       k9cKA4RFWAfV / HdbwdNt2g1W / eoEdQsDhEVYO838uqxg jWzf1X1qxPWLQwQFmH1       jfPP6AyoYdP / hVlvVavW3urVGuqvKUTCIqypH0Ybf9p0g1Cq9Wb10W80 / nrSIizC       mrlgmGSmTf8UV2VRrXOlvvpM83JFRliEVTqht8Grpl7Pcaxa45b68Rnuc XU 3aE       9cbC2oBYOXrgVH29nv1Y1f Z v45rglrOe6D5XthqTZ9 z7VvK3e5rZz1dPm9c5V       7z3qveca 14e7 / H Jaw3T1gbRCvHEbaq5zh / f1 / 1tvq p123WnVu853zJbX / hoRF       WP mp0oAW30PTjV / P3d / XfW1 r7neN3mVOdjn / t8eREWYS0LaxNE2 / S3yqLq2z j       Pat3vtc6vbWNPa / YCIuwliW0l0kljNGmr / r2zxitsY2vHLN teeV0uzbEBZhXRJW       E0oljB50VU9bu9fbG7v3er1nGHsusREWYX0Ia9ucK8fKvN5GX12719sbu / d6vWcY       I6zfNgggvg6IakOP3n3Vt1LvrX1rX2 tbWzlGPUa / zruvvLdSlgS1ukfkBURVHN6       0FY9W73XNxq793qj5xh / HrkRFmF1JbEig9mc3iafzW 1Xt9orPXMzqNe488joSvf       grAIi7BemIErMkiYS1gvDOsseWy1CtCqf1bvrT2b32q9vtFY65mdR73GJaxyA4Dk       sZDMNvJWq75H1T r99aezW 1Xt9orPXMzqNe449l8V7vW8KSsKbimslgVusBOpvf       ar2 0VjrmZ1HvcYJawo QB4PyGwjb7XVb1Kt06uP1u7NPY6Nevfjx57e / X6 68fz       9xXvXMKSsEpx9WRQjY1grfq2 qh3P36vdfZrun5 qREWYd1NEHuJjDb / fs7setS /       ja8eszXUnl9OvW9EWIT1UGF9VjhklSmannxuGSMswloS1hXRbFKZwbgqnc / Mmz1f       LVd6hEVYU7kcN / eqRI59x / vVdW6Zd3yW 1xBHb8dYRHWtwhrA / ErjiPg7l9HVtu3       JCzCuiSsVdGsiuKe0lp9pnm5EiMswvpWYTV5fEZcbQ3nXBGtfjvCemFhrULwbPNW       5PVsv9nveYwsCYuwLicsm / Mxm9N7Pr9nwiIswsJADAOEBdYYWCWOc J4t3dCWIRF       WBiIYYCwwBoD67ulCX / vOVESFmERFgZiGCAssMbAKnGcE8e7vRPCIizCwkAMA4QF       1hhY3y1N HvPiZKwCIuwMBDDAGGBNQZWieOcON7tnRAWYREWBmIYICywxsD6bmnC       33tOlIRFWISFgRgGCAusMbBKHOfE8W7vhLAIi7AwEMMAYYE1BtZ3SxP 3nOiJCzC       IiwMxDDwNwAAAP // wDatNAAACdVJREFU7dxRkus2DkDRrGU srDZ / x6SuBK olkE       TVF2v0bjuColCQJItXl5he5k5o8 /// F / V / zjO8AABjIw8EeGh / SMNhMGMPBggLB0       mDpsDKRhgLDAmgZWXZYui7AIi7AwkIYBwlr tcbP7oD3QEG7jNAWISV5u1qw9 / f       8Nm / Q8IiLMJaMJB9g / 05yesBaxv / I2QFBbf80 / bVH6ez3WChLXYSIT1OfBsat / t       CQOERVi6vwUDJ5tKzedkTFgXYd3pugD7OWB9t7W / W8IiLB3WRQZI8 / dJk7Auwvqd       OqzoWXY31N36cZ5ovCg 1t 9juZ5xO OfaV 9Rz9vStjyv1XkoT1DYTVQxyd98BG       OWO8r nPx7zouq ZnUd1J / HZ LuxK / M9xtz57M7d5 2MO8vpx3C 7t4IK5mwZsCv       YuMGWOXO7o31 / fUs / 26sH // V d25VvWv5u7vr8a5cq8f0 / lcXISVRFhXwO9zG / h9       7Op5G2M8Xh1nN3 cZ3a9O9Zp3mzOMXY69qpunMP1s7gI64cLa7U5du9Fm2a3 / iQv       mrPFT8a8UtPmiY5XxrqaG80p7v8P6 / IfY3fguwrWzpi / Myf6eT75TNGcj / hXfFbz       7z7DbIydZ5 / Vifmj 2VZ3QF1BdwOxL87Z / b8s2ea5fWxWU0U6 vaeZQ7i7ea8TjL       HWNjTX895s6u / zxfJY / xsYa14SVUlgjuCPor65P68e6x3X7zO6tYq3u1XE2xqua       dn9W22ItZ3VsueNxVdPujTXjdctbHcca14SVSlgRsCvo 3ufqo / GfRXvny06n40R       5fbxWV0f63Oj8z6 / P4 / yW7zPXZ23 / NVxVV / 1nj 6J / mj wrQFfTt3ifrV2NH99pz       rY5j7Sq3vzfWjdd9bnQ 1rTrKL / FW96rY8tfHV NUfE YRHWas / 8undnc / wa5OLJ       OOdO Vgzuz4d57Tunc8wG6tSjLAIa2cfbv / 6vDXYZtK4EXfKxprZ9ek4O3XvzJk9       e / UYYRHW1h5bbZStAQ6Sxjl3hhhrZten4 zUvTNn9uzVY4RFWFt7LNooW8WHSeOc       O8OMNbPr03F26t6ZM3v26jHCIqytPTbbKFuFN5LGOXeGGmtm16fj7NS9M2f27NVj       hEVYW3ts3ChbRV3SSf07asYxHtc7n9O6nbF3c2bPUD1GWIS1tX / GjbJTNNb01yf1       JzX9nO38dJzTujav4 / P / kPnk yAswtrZh0 // lnCn4BWMJ2Oc1Mye43Sc07rZM4id       yYuwCGtnH6YR1uOHeSWDnR94NsZp3WwsMcJ6Ceo7IPkEtHfH / Or6u / M91mHnM1uv       07p rDtj3Kntn8E5YRHWYjetNsii7Netvv5XcHHS58 / OF6W / bp3WtQHG hbfOY61       7Xqn9pHT8k ObY6T2p9e41dCvxK2 / bE89hthmfjfzT5 / PN pf SMdY / rr / rM5r46       fzRGFB9 / tiivcpywFsIaAbpzvYJsZ9zvVL / zvI c2TPv1kb1jzG / 4jN79ha7On r       i47ReFF 5ThhEVa0X57i4yZ5uvmhi3HOdv2h6Z6GbXNFx6fkD11Ec1eOExZhbW23       cZNsFd1MGufsr28O / bK8n2t2 / nKANyTM5q0eIyzC2tpas42yVXgjaTZnH7sx9MvS       fp7V cuBbiSs5q16j7AIa2tLzTbIVuGQ1MYZwtPLlrs6TguDYBsnuP0Ubrk7x6fC       N17szF0th7AIa2uLrTbG1gD / JPVj7NT0 a / OV ONTAvcdm s2blutXePO3NVzSGs       hbCqQnHyc6826cl4n6xZPWu7d3f Ns7O8e5cleoJi7CeOp fDj BnP0X5t FC8Ii       rJTCauK5upFa3ep4dUz5XydBwiKs1MLqxbMSR5 / 36nw1jntfJ6fZd01YhPVjhPVK       RDv3Z5tE7PdKqv / CYuwCKszWb85nH8fUbW1ICzCIqz / hNU2heP3E1VbE8IiLML6       R1htQzh X1k91oawCCvlZu1 i7t1SlDfW1Dj hAWYaUUVg / yVWP1tc4JK / 0GAHEu       iK1XnfXSYemwvGAwkIYBwgJrGlh1UnU6qWitCYuwCAsDaRggLLCmgTV664rX6bwI       i7AICwNpGCAssKaBVSdVp5OK1pqwCIuwMJCGAcICaxpYo7eueJ3Oi7AIi7AwkIYB       wgJrGlh1UnU6qWitCYuwCAsDaRggLLCmgTV664rX6bwIi7AICwNpGCAssKaBVSdV       p5OK1pqwCIuwMJCGAcICaxpYo7eueJ3Oi7AIi7AwkIYBwgJrGlh1UnU6qWitCYuw       CAsDaRggLLCmgTV664rX6bwIi7AICwNpGCAssKaBVSdVp5OK1pqwCIuwMJCGAcIC       axpYo7eueJ3Oi7AIi7AwkIYBwgJrGlh1UnU6qWitCYuwCAsDaRggLLCmgTV664rX       6bwIi7AICwNpGCAssKaBVSdVp5OK1pqwCIuwMJCGAcICaxpYo7eueJ3Oi7AIi7Aw       kIYBwgJrGlh1UnU6qWitCYuwCAsDaRggLLCmgTV664rX6bwIi7AICwNpGCAssKaB       VSdVp5OK1pqwCIuwMJCGAcICaxpYo7eueJ3Oi7AIi7AwkIYBwgJrGlh1UnU6qWit       CYuwCAsDaRggLLCmgTV664rX6bwIi7AICwNpGCAssKaBVSdVp5OK1pqwCIuwMJCG       AcICaxpYo7eueJ3Oi7AIi7AwkIYBwgJrGlh1UnU6qWitCYuwCAsDaRggLLCmgTV6       64rX6bwIi7AICwNpGCAssKaBVSdVp5OK1pqwCIuwMJCGAcICaxpYo7eueJ3Oi7AI       i7AwkIYBwgJrGlh1UnU6qWitCYuwCAsDaRggLLCmgTV664rX6bwIi7AICwNpGCAs       sKaBVSdVp5OK1pqwCIuwMJCGAcICaxpYo7eueJ3Oi7AIi7AwkIYBwgJrGlh1UnU6       qWitCYuwCAsDaRggLLCmgTV664rX6bwIi7AICwNpGCAssKaBVSdVp5OK1pqwCIuw       MJCGAcICaxpYo7eueJ3Oi7AIi7AwkIYBwgJrGlh1UnU6qWitCYuwCAsDaRggLLCm       gTV664rX6bwIi7AICwNpGCAssKaBVSdVp5OK1pqwCIuwMJCGAcICaxpYo7eueJ3O       i7AIi7AwkIYBwgJrGlh1UnU6qWitCYuwCAsDaRggLLCmgTV664rX6bwIi7AICwNp       GCAssKaBVSdVp5OK1pqwCIuwMJCGAcICaxpYo7eueJ3Oi7AIi7AwkIYBwgJrGlh1       UnU6qWitCYuwCAsDaRggLLCmgTV664rX6bwIi7AICwNpGCAssKaBVSdVp5OK1pqw       CIuwMJCGAcICaxpYo7eueJ3Oi7AIi7AwkIYBwgJrGlh1UnU6qWit / wYl67h8sCnn       egAAAABJRU5ErkJggg ==

我尝试使用

以HTML格式显示
<img src="data:image/png;base64,iVBORw0KGgoAAA....." />

如何解决这个问题?

感谢。

1 个答案:

答案 0 :(得分:0)

您的代码似乎正确,请尝试将BASE64格式替换为:

String imgString = Base64.encodeToString(byteFormat, Base64.DEFAULT);

如果仍无效,请查看此answer

希望这有帮助!