0

In my application i want the image which is inside the linear layout.So for that i have used

    view.setDrawingCacheEnabled(true); // this is coming as undefined
    view.buildDrawingCache(); // this is coming as undefined
    Bitmap cache = view.getDrawingCache(); //here am getting null

But whenever i debug the code i am getting null at " view.getDrawingCache()".

Code

public static void saveLayout(View view) {
        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        Bitmap cache = view.getDrawingCache();
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(Environment.getExternalStorageDirectory() + "/ss/file.png");
            cache.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
            fileOutputStream.flush();
            fileOutputStream.close();
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            view.destroyDrawingCache();
        }
    }

Usage

saveLayout(ll) // here ll is my linear layout

Please lemme know where i went wrong

androGuy
  • 855
  • 2
  • 8
  • 11

1 Answers1

0

Can you try below code?

view.buildDrawingCache(true);
Bitmap bitmap = view.getDrawingCache(true);

Also remove:

view.setDrawingCacheEnabled(true);
Green goblin
  • 9,898
  • 13
  • 71
  • 100