Convert Image saved in resource.mipmap to Bitmap

1

I have an image in the mipmap folder of my project, I would like to convert that image to Bitmap .
I tried this way but it does not work for me since it tells me that

  

(R.mipmap.imagen_deseada) can not be applied to this method (BitmapFactory) .

Bitmap bitmap = BitmapFactory.decodeFile(R.mipmap.imagen_deseada);
articulo.setImg(bitmap);

How can I do it?

    
asked by Humberto Arciniega 21.09.2018 в 19:06
source

1 answer

2

What you can do is the following

Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.mipmap.imagen_deseada);
articulo.setImg(bitmap);

Where context is this (in Activity) or getActivity() (in Fragment)

Remember that the size of the image is important, as much weight as high resolutions could bring you a OutOfMemoryException

    
answered by 22.09.2018 / 20:37
source