decode Drawable from Base64 String - Android Graphics

Android examples for Graphics:Drawable

Description

decode Drawable from Base64 String

Demo Code


//package com.java2s;
import android.content.Context;

import android.graphics.drawable.Drawable;
import android.util.Base64;

import java.io.*;

public class Main {
    public static Drawable decodeDrawable(Context context, String base64) {
        Drawable ret = null;//from w ww.  ja  va  2  s  .  c  o  m
        if (!base64.equals("")) {
            ByteArrayInputStream bais = new ByteArrayInputStream(
                    Base64.decode(base64.getBytes(), Base64.DEFAULT));
            ret = Drawable.createFromResourceStream(context.getResources(),
                    null, bais, null, null);
            try {
                bais.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return ret;
    }
}

Related Tutorials