Android,糟糕的base-64错误而数据url解码。

时间:2022-11-03 18:34:32

I want to decode 'canvas.dataURL() on javascript' in android.

我想要解码android中javascript的canvas.dataURL()。

byte[] decodedString = Base64.decode(var, Base64.DEFAULT);
Bitmap bm = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

But it gives error :

但它给出了错误:

E/AndroidRuntime(29827): java.lang.IllegalArgumentException: bad base-64

My data url sample:

我的数据url示例:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAACWCAYAAABkW7XSAAAgAElEQVR4Xu19CXhV5dXum+Hk5GQeSJinMIQQxpCJeQijoAK1VbxardbWqrVPW1uv/a3a1qq1/av2tnayDtTp1wriDMgUCEnITBKmAILMEELmk5wk5/zv2ic7pf9TCVeu93E/e22fCJx99j7f967s96y1vnetL6CsrMw3Z84cNDQ0QI6goCCEhITA7XYjICAAu3fvRlpaGjo6OozzgYGBxutdXV3Gv3k9LnV9RUUFpk+fjqampp77y7Xx8fHo6GzFli0fIj19DuAFHA7+BANtbiA4sB883i6UlmzH5CmTeW0cf/im4Hr+cCwBgUCHB0W7NiE7LQdBGIYOdCLEUYdARyva2v33K9hZjMyMmejs6uT1PjhCnAgPD0V9/XljPDWHP8WopCGcON/v5C1bwmWWGDAoChfqTyMvbztmTJ+Ldnco59yKoJAO/injAzo7AlFRvQcTJ0/gPzwcnoO3iSeGQJfvNLw+oLy0CpMnj4fP4UMAX/dyXPC5+GHE0edFSVEB5s6Z9Zn4l5aWXhLf/xfnJ08WfBFgAKKHIvAlRkB+SflYycPtQGdnp0FQkyZNMgjpf5KTkMy6deuwePFiNDc3/8u0Put6r5ckwyM4ONggQ3nAxo0bh0GDBpFUmtHacoF/H4jDh07w84H8vM3ImbcYre2hCA0OQ1vnecTFxcPd7kCruxUVewsxcVIKQH6Az0dq8cLnDYTL0RfujhZUlG8ngYyHi7zDt/McEB2ViMbGRgSRJLbnbsLUaVNJWk60tJA9fGTIAC/CYwLQ0tiFvVVHkZ01HcHONgQFe3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LNWz7CH//2Z74nHDVVJzFq3BiDHBpxEmFR9Pq4whfEZHaX103PZhemZWdzdc6DaenZePCBn6OxvosJ/Xg8/MBv8OgvH0KL5wjWb3yLzpWX8oVmvLt+Gz9dFh9P4cD+vcjOWIQli68hmTqx5KocMmgrc1lOrH1zOwYNHI5dxZuxafs6Sig8DAlJOiFR6GzvpC/VisrS/fjFg89R9uDDidOVJE2+VnPMGG8HjmN31S6ulE6WqJO5tUDi409k/Tv8Tfy+qPOmx9z95fWl/4XVAdobgYDedFhXqvMRnZbosFpamOTp9iZkZUp+hKd2V5YxLzbZSLq7Wzz0kEQmwNxYQH96N+OQNXkq5s5dgNUvvI7cks1cM6zjY9+OCBLhhc4LKGTYlc7kt7hYnV3UjkkWm0QQGcFAk1z4s588jeEDpiJ/61G8+/Z7OOmuZrAn73MjfUoqkkYNwaw5OXjil8/i4LG9JJzTDP0kSIzBDdffglAX81iUTb306h9F9oXU5Lm8LgvLls/Dgz+9H089838wc9ZM3q+Lebo2JI9JwH3fvx8xYRPw5msfYPDgAcjKmsu/b8ausjycPJ+PjkB6aUzWk/+Rm5tPHdbCntVZyQtKCGzKRnrTuV2pfeR61WHZmwSsNPtedVimjurz6oAEDLmH6Z2JxMHMi3WrAsDcNjooFhVZQHnZLszMmo9AT3/ccdv3kDNrFsPELjz/l7eQW7YVZTs/5ureBK4MtiAyKhy1rWfR2tliEEZ0VCR25G5F2pSJxspgIBP5P773CaQkzcWa13JRWlaM9z/6MzLmjUMUEtCMJoweNsDQTdUcPImtFKHuqcjl6l4qV/CS8MtHf00JhAf7D1bjP5/+Bb0hJwrzDmHO3Pn4ylevwoIF83DoyKd44vEn0dhSxzC2k4n5N+g1+nDuOBcxCvfiDy8+gwlJmRjUPxUDBidizuLRuO3Oazm4ZjRzXrFxUag732jkBOXnww8/NLxXSbLLj+nlfl78TfuZq4z79u0zVmdlEUQO+VN1WFZ6ZO091l51WFeq

How I can decode my data url in javascript?

如何在javascript中解码我的数据url ?

1 个解决方案

#1


3  

You should remove the data:image/png;base64,

您应该删除数据:image/png;base64,

Try with

试着用

var = var.replace("data:image/png;base64,","");
byte[] decodedString = Base64.decode(var, Base64.DEFAULT);
Bitmap bm = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

#1


3  

You should remove the data:image/png;base64,

您应该删除数据:image/png;base64,

Try with

试着用

var = var.replace("data:image/png;base64,","");
byte[] decodedString = Base64.decode(var, Base64.DEFAULT);
Bitmap bm = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);