Search code examples
androidbitmapscreenshotblur

How to take a screenshot/bitmap of the area behind an ImageView/any UI component in Android?


let's suppose I have an ImageView, Grid or whatever control. What I want to do is take a screenshot of what's behind this control, let's say another controls that hold a background image or anything there could be. Is there any way I could do this? I thought of the getDrawingCache(); method but that would take the top control too.

I want to do this so I can make the blurry transparent effect of what is behind of my top controls. I already have a blurring method, I just need to take the exact picture of the background. Any help will be greatly appreciated!


Solution

  • You can use the getDrawingCache() method on any view, so if you have a reference to your background view it should work with something like this:

    <your background view>.setDrawingCacheEnabled(true);
    Bitmap contentBitmap = Bitmap.createBitmap(<your background view>.getDrawingCache());
    <your background view>.setDrawingCacheEnabled(false);
    

    The contentBitmap should now contain a bitmap of what was in that view.