Forum Xamarin.Forms

Listview To Image

fabiorosanetfabiorosanet Member
edited May 2020 in Xamarin.Forms

Hi!
I have a listview, where not all items are visible in screen (I have scroll in this list)....
Have any way to get screenshot for all list items? Or mount a image stacking all list items? Including invisible items...?

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    Do you want to get a long screenshot of your phone's listview?
    Then you might check to see if your current phone model has the ability to take long screenshots first.

    Or do you want get all the data of the current list items?

  • fabiorosanetfabiorosanet Member

    Yes, I need long screenshot of my listview...

  • jezhjezh Member, Xamarin Team Xamurai

    For this function ,you can refer to the following code:

    public static Bitmap getWholeListViewItemsToBitmap() {
    
        ListView listview    = MyActivity.mFocusedListView;
        ListAdapter adapter  = listview.getAdapter(); 
        int itemscount       = adapter.getCount();
        int allitemsheight   = 0;
        List<Bitmap> bmps    = new ArrayList<Bitmap>();
    
        for (int i = 0; i < itemscount; i++) {
    
            View childView      = adapter.getView(i, null, listview);
            childView.measure(MeasureSpec.makeMeasureSpec(listview.getWidth(), MeasureSpec.EXACTLY), 
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    
            childView.layout(0, 0, childView.getMeasuredWidth(), childView.getMeasuredHeight());
            childView.setDrawingCacheEnabled(true);
            childView.buildDrawingCache();
            bmps.add(childView.getDrawingCache());
            allitemsheight+=childView.getMeasuredHeight();
        }
    
        Bitmap bigbitmap    = Bitmap.createBitmap(listview.getMeasuredWidth(), allitemsheight, Bitmap.Config.ARGB_8888);
        Canvas bigcanvas    = new Canvas(bigbitmap);
    
        Paint paint = new Paint();
        int iHeight = 0;
    
        for (int i = 0; i < bmps.size(); i++) {
            Bitmap bmp = bmps.get(i);
            bigcanvas.drawBitmap(bmp, 0, iHeight, paint);
            iHeight+=bmp.getHeight();
    
            bmp.recycle();
            bmp=null;
        }
    
    
        return bigbitmap;
    }
    

    Refer:https://stackoverflow.com/questions/12742343/android-get-screenshot-of-all-listview-items

Sign In or Register to comment.