3

I simply need a Screenshot as an Bitmap of my ListView. I can't figure out how to do this. The bitmap of the screen ist than used to blur it and set is as an background in another Fragment. Where do i take Screenshot from? BaseAdapter or my Fragment which contains the ListView? or in the new Fragment that gets opened after clicking an Item in the ListView?

UPDATE: Im calling the method inside a ViewTreeObserver from my New Fragment. The Method loadBitmapFromView works perfectly. My Problem now is i don't know how to get hold of the ListView which i want the picture from. The Params i use mContainer,mContainer.getWidth(),mContainer.getHeight() should change to the one from my ListView. (The params right now are form the new Fragment for testing purposes)

private void applyBlur() {

    mContainer.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            mContainer.getViewTreeObserver().removeOnPreDrawListener(this);
            mContainer.buildDrawingCache();

            blur(MOKListViewFragment.loadBitmapFromView(mContainer,mContainer.getWidth(),mContainer.getHeight()), mContainer);
            return true;
        }
    });
}

This is how i call my new fragment from my BaseAdapter of the ListView which i actually want my picture from.

ImageView imageView = (ImageView) rowView.findViewById(R.id.thumb_button_1);
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MOKPagerFragment pagerFragment = new MOKPagerFragment();
                    FragmentTransaction fragmentTransaction = ((Activity) mContext).getFragmentManager().beginTransaction();
                    fragmentTransaction.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);
                    fragmentTransaction.add(R.id.fragment_container, pagerFragment);
                    fragmentTransaction.addToBackStack(null);
                    fragmentTransaction.commit();
                }
            });

Sorry if this is confusing.

Daniel Storch
  • 327
  • 1
  • 3
  • 15
  • 1
    see this link http://stackoverflow.com/questions/12742343/android-get-screenshot-of-all-listview-items?rq=1 – Vaishali Sutariya Sep 26 '14 at 11:59
  • i think thats more than what i need. I don't need the screenshot of all items included the ones that are not showing. Simply need a screenshot of the current state of the ListView so i can blur that bitmap for background purposes. – Daniel Storch Sep 26 '14 at 12:10

1 Answers1

0
if your phone is rooted try this

Process sh = Runtime.getRuntime().exec("su", null,null);

                OutputStream  os = sh.getOutputStream();
                os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
                os.flush();

                os.close();
                sh.waitFor();

then read img.png as bitmap and convert it jpg as follows

Bitmap screen = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+   File.separator +"img.png");

now you can use screen bitmap

refrence from here

Community
  • 1
  • 1
Vaishali Sutariya
  • 5,093
  • 30
  • 32