import android.app.*; import android.content.*; import android.graphics.*; import android.graphics.drawable.*; import android.util.*; import android.view.*; import com.google.appinventor.components.annotations.SimpleFunction; import com.google.appinventor.components.runtime.*; import com.google.appinventor.components.runtime.util.*; public class Base64ImageToComponent extends AndroidNonvisibleComponent { private final Context context; private final Activity activity; private final Form form; public Base64ImageToComponent(ComponentContainer container) { super(container.$form()); this.form = container.$form(); this.activity = form.$context(); this.context = activity.getApplicationContext(); } @SimpleFunction(description="Create bitmap from base64String and set as background to component. For some components, you will have to use the component's " + "image and backgroundColor blocks to remove any existing image or colour for this to be visible") public void SetBackgroundImageFromBase64(AndroidViewComponent component, String base64String) { final View view = component.getView(); byte[] decodedString = Base64.decode(base64String, Base64.DEFAULT); Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); Drawable backgroundImageDrawable = new BitmapDrawable(context.getResources(), decodedByte); backgroundImageDrawable = backgroundImageDrawable.getConstantState().newDrawable(); ViewUtil.setBackgroundImage(view, backgroundImageDrawable); } @SimpleFunction(description="Clear base64Image from background of component") public void ClearBackgroundImage(AndroidViewComponent component) { final View view = component.getView(); ViewUtil.setBackgroundImage(view, null); }