package com.mapbox.mapboxsdk.testapp.utils; import android.graphics.Bitmap; import android.graphics.Canvas; import android.support.annotation.NonNull; import android.view.View; /** * Converts a View to a Bitmap so we can use an Android SDK View as a Symbol. */ public class ViewToBitmapUtil { public static Bitmap convertToBitmap(@NonNull View view) { view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas); return bitmap; } }