Skip to content Skip to sidebar Skip to footer

Android: Taking A Screenshot For All View In Scrollview

I try to take a ScreenShot for all view in ScrollView, my ScrollView has content that spills out of the screen (hence scrolling made possible), how can I ensure that the screenshot

Solution 1:

Try this:

Bitmapbitmap= Bitmap.createBitmap(scrollView.getChildAt(0).getWidth(), scrollView.getChildAt(0).getHeight(), Bitmap.Config.ARGB_8888);
Canvasc=newCanvas(bitmap);
scrollView.getChildAt(0).draw(c);

You can get the screenshot any of the child layout of scrollview.

Solution 2:

You can use this code to take a screenshot of your full ScrollView the same code can be adapted to all kind of Views

Code :

Viewu= findViewById(R.id.scroll_pp);
        u.setDrawingCacheEnabled(true);                                                
        ScrollViewscroll_pp= (ScrollView) findViewById(R.id.scroll_pp);
        inttotalHeight= scroll_pp.getChildAt(0).getHeight();
        inttotalWidth= scroll_pp.getChildAt(0).getWidth();
        u.layout(0, 0, totalWidth, totalHeight);    
        u.buildDrawingCache(true);
        Bitmapb= Bitmap.createBitmap(u.getDrawingCache());             
        u.setDrawingCacheEnabled(false);

        //Save bitmapStringextr= Environment.getExternalStorageDirectory().toString() +   File.separator + "Folder";
        StringfileName="Test.jpg";
        FilemyPath=newFile(extr, fileName);
        FileOutputStreamfos=null;
        try {
            fos = newFileOutputStream(myPath);
            b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.flush();
            fos.close();
            MediaStore.Images.Media.insertImage(getContentResolver(), b, "Screen", "screen");
        }catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

Post a Comment for "Android: Taking A Screenshot For All View In Scrollview"