pents90 / svg-android

Support for scalable vector graphics in Android
773 stars 367 forks source link

can I pass Base64 encoded string to "SVGParser.getSVGFromString" ? #13

Open sumitsh87 opened 10 years ago

sumitsh87 commented 10 years ago

My SVG image (Base64 encoded) is "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTAwIiB3aWR0aD0iMTAwIj48Y2lyY2xlIGN4PSI1MCUiIGN5PSI1MCUiIHI9IjQ5LjEiCiAgICAgICAgICBmaWxsPSJ3aGl0ZSIvPiI8dGV4dCB4PSIyNSUiIHk9IjYwJSIgc3R5bGU9ImZvbnQtZmFtaWx5OiBjb3VyaWVyIG5ldzsgZm9udC13ZWlnaHQ6bm9ybWFsOyBmb250LXN0eWxlOiBub3JtYWwiIGZvbnQtc2l6ZT0iNDBweCIgPlBVPC90ZXh0Pjwvc3ZnPgogICAgICAgIA=="

when I set it to ImageView in ANdroid using SVG svg = SVGParser.getSVGFromString("data:image......A==") imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); PictureDrawable pictureDrawable = svg.createPictureDrawable(); stubBitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(), pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888); imageView.setImageBitmap(stubBitmap);

I get the following error: E/AndroidRuntime(28379): com.larvalabs.svgandroid.SVGParseException: org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 350: not well-formed (invalid token)

Please help.

megamattron commented 10 years ago

No, you can't pass in the base64 encoded string quite like that, you'll need to decode it first. That method basically expects properly formed XML in a plain String.

victorsosa commented 8 years ago

That's a https://en.wikipedia.org/wiki/Data_URI_scheme form