How to set a bitmap from resource

前端 未结 6 1232
温柔的废话
温柔的废话 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:26

    If the resource is showing and is a view, you can also capture it. Like a screenshot:

    View rootView = ((View) findViewById(R.id.yourView)).getRootView();
    rootView.setDrawingCacheEnabled(true);
    rootView.layout(0, 0, rootView.getWidth(), rootView.getHeight());
    rootView.buildDrawingCache();
    
    Bitmap bm = Bitmap.createBitmap(rootView.getDrawingCache());
    
    rootView.setDrawingCacheEnabled(false);
    

    This actually grabs the whole layout but you can alter as you wish.

提交回复
热议问题