Reputation: 45
I'm trying to get an image from the folder /drawable but I receive null when api > 19. Does anyone know what the problem is?
All images I use are vectors.
dog.setImagen(BitmapFactory.decodeResource(getResources(), R.drawable.dog));
Thanks in advance
Upvotes: 1
Views: 1741
Reputation: 45
I have solved my problem with this code.
private Bitmap getBitmap(Drawable vectorDrawable) {
Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
vectorDrawable.draw(canvas);
return bitmap;
}
Thanks everyone!
Upvotes: 2
Reputation: 4959
Try with this
Bitmap bm = ((BitmapDrawable) getResources().getDrawable(R.drawable.dog)).getBitmap();
dog.setImagen(bm);
Upvotes: 1