5

The main issue is saving the whole scroll view as a bitmap image rather than just what appears on the screen. Is there a way to save whole scroll view, and if so how?

user3693635
  • 51
  • 1
  • 4

3 Answers3

2

Make a RelativeLayout or LinearLayout in your ScrollView to get Bitmap from Layout.

Organize this way:

public class ActivityA extends Activity {

LinearLayout PP_Ll;
Button btn_capture;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

PP_Ll = (RelativeLayout) findViewById(R.id.PP_Ll);
Button btn_capture= (Button) findViewById(R.id.btn_capture);

btn_capture.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

        Bitmap bitmap = takeScreenshot();
        saveBitmap(bitmap);

        }
    });

public Bitmap takeScreenshot() {

    View rootView = getWindow().getDecorView().findViewById(R.id.PP_Ll);
    rootView.setDrawingCacheEnabled(true);
    return rootView.getDrawingCache();

}

public void saveBitmap(Bitmap bitmap) {

    String root = Environment.getExternalStorageDirectory().toString();
    File newDir = new File(root + "/Folder");
    newDir.mkdirs();
    Random gen = new Random();
    int n = 10000;
    n = gen.nextInt(n);
    String fotoname = "Photo-" + n + ".jpg";
    File file = new File(newDir, fotoname);
    if (file.exists())
        file.delete();
    try {
        FileOutputStream fos = new FileOutputStream(file);
        bitmap.compress(CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
        Toast.makeText(getApplicationContext(),
                "Saved in folder: 'Folder'", Toast.LENGTH_SHORT).show();

    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }

}
}}

Your RelativeLayout will be saved in certain directory as a BitMap. Good luck.

Note: You have to insert your imageviews, textviews etc. into your RelativeLayout in .xml file that all can go into screenshot.

Umit Kaya
  • 5,771
  • 3
  • 38
  • 52
0

try below code:-

public static Bitmap loadBitmapFromView(View v, int width, int height) {
    Bitmap b = Bitmap.createBitmap(width , height, Bitmap.Config.ARGB_8888);                
    Canvas c = new Canvas(b);
    v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
    v.draw(c);
    return b;
}

see below link

Take a screenshot of a whole View

Community
  • 1
  • 1
duggu
  • 37,851
  • 12
  • 116
  • 113
  • i have tried that but it is not working properly it only gives the image of screen which is shown not the whole scroll view which is below of screen so please help me out for this problem it is urgent please help me thanks in advance @Golu – user3693635 Jun 02 '14 at 04:22
  • @user3693635 see new link – duggu Jun 02 '14 at 04:26
-1

Possible solution, you can create a emulator of larger screen size maybe 10inch, and run your app on it, If your listview fits into the screen, you can take a screen shot of it.

zIronManBox
  • 4,967
  • 6
  • 19
  • 35