How to take screenshot of a layout in android

后端 未结 1 1006
猫巷女王i
猫巷女王i 2021-01-18 22:18

I want to save my frame layout into gallery by taking the screen shot of the layout. This code works on a project(Name: Trial), but when I tried the same code on othe projec

1条回答
  •  悲哀的现实
    2021-01-18 22:41

    Have you got the

    
    

    Declared in your manifest?

    Also if you want the entire view try this:

    view1.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(view1.getDrawingCache());
    

    Oh and this may save you some time:

    private void openScreenshot(File imageFile) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        Uri uri = Uri.fromFile(imageFile);
        intent.setDataAndType(uri, "image/*");
        startActivity(intent);
    }
    

    Src: How to programmatically take a screenshot in Android?

    0 讨论(0)
提交回复
热议问题