How to set a bitmap from resource

前端 未结 6 1252
温柔的废话
温柔的废话 2020-12-22 15:52

This seems simple, I am trying to set a bitmap image but from the resources, I have within the application in the drawable folder.

bm = BitmapFactory.decodeR         


        
6条回答
  •  悲&欢浪女
    2020-12-22 16:16

    just replace this line

    bm = BitmapFactory.decodeResource(null, R.id.image);
    

    with

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.YourImageName);
    

    I mean to say just change null value with getResources() If you use this code in any button or Image view click event just append getApplicationContext() before getResources()..

提交回复
热议问题