use of android.graphics.drawable.VectorDrawable in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class UtilsTest method createIconWithDrawable_VectorDrawable.
@Test
public void createIconWithDrawable_VectorDrawable() {
final VectorDrawable drawable = VectorDrawable.create(mContext.getResources(), R.drawable.ic_settings_accent);
final IconCompat icon = Utils.createIconWithDrawable(drawable);
assertThat(icon.getBitmap()).isNotNull();
}
use of android.graphics.drawable.VectorDrawable in project Stringlate by LonamiWebs.
the class ContextUtils method drawableToBitmap.
public Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (drawable instanceof VectorDrawable || drawable instanceof VectorDrawableCompat)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
drawable = (DrawableCompat.wrap(drawable)).mutate();
}
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
} else if (drawable instanceof BitmapDrawable) {
bitmap = ((BitmapDrawable) drawable).getBitmap();
}
return bitmap;
}
use of android.graphics.drawable.VectorDrawable in project memetastic by gsantner.
the class ContextUtils method bitmapToDrawable.
public Bitmap bitmapToDrawable(@DrawableRes int drawableId) {
Bitmap bitmap = null;
Drawable drawable = ContextCompat.getDrawable(_context, drawableId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (drawable instanceof VectorDrawable || drawable instanceof VectorDrawableCompat)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
drawable = (DrawableCompat.wrap(drawable)).mutate();
}
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
} else if (drawable instanceof BitmapDrawable) {
bitmap = ((BitmapDrawable) drawable).getBitmap();
}
return bitmap;
}
Aggregations