Android : taking Screenshot of the selected area programmatically

后端 未结 2 862
礼貌的吻别
礼貌的吻别 2021-01-15 04:08

My code is as follow :

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main         


        
2条回答
  •  情书的邮戳
    2021-01-15 04:26

    You can wrap the contents in a layout for example LinearLayout and follow the above code for taking screenshot by using the methods on the wrapped layout.

     Bitmap bitmap;
     ViewGroup v1 = findViewById(R.id.layout_id);
     v1.setDrawingCacheEnabled(true);
     bitmap = Bitmap.createBitmap(v1.getDrawingCache());
     v1.setDrawingCacheEnabled(false);
    

提交回复
热议问题