Base64 image and html.fromhtml android

My data is stored in html format on db.

The image is saved in base64 format (as a string in db).

I am trying to show this data.

My textView is configured as follows:

SetText (Html.fromHtml (content));

all html tags in 'content' are displayed correctly. Except for the 'img' tag (which contains the base64 encoded image).

So my question is: can the 'img' tag from 'Html.fromHtml' decode a base64 image string?

ps: the place where the tag shows only a small gray square. No mistakes.

THX

+3
source share
1 answer

Use Html.fromHtmlin conjunction with your own implementation Html.ImageGetter.

See here .

Html.ImageGetter.getDrawable Base64 ( android.util.Base64) BitmapFactory.decodeByteArray, Bitmap, BitmapDrawable .

:

Html.fromHtml(content, new Html.ImageGetter() {
        @Override
        public Drawable getDrawable(String source) {
            byte[] data = Base64.decode(source, Base64.DEFAULT);
            Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);                
            return new BitmapDrawable(getResources(), bitmap);
        }
}, null);
+1

All Articles