how to generate and save image of layout in android

Solutions on MaxInterview for how to generate and save image of layout in android by the best coders in the world

showing results for - "how to generate and save image of layout in android"
Alberto
28 Nov 2020
1LinearLayout content = findViewById(R.id.rlid);
2content.setDrawingCacheEnabled(true);
3Bitmap bitmap = content.getDrawingCache();
4File file,f;                    
5if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) 
6    {  
7         file =new File(android.os.Environment.getExternalStorageDirectory(),"TTImages_cache");
8         if(!file.exists())
9        {
10          file.mkdirs();
11
12         } 
13         f = new File(file.getAbsolutePath()+file.seperator+ "filename"+".png");
14    }
15  FileOutputStream ostream = new FileOutputStream(f);                                   
16  bitmap.compress(CompressFormat.PNG, 10, ostream);
17  ostream.close();
18
19 } 
20 catch (Exception e){
21 e.printStackTrace();
22}
23
similar questions