1

I want make JPG image of my one cardview and want share it on select overflow menu. My XML file is like below, How can I make screenshot of one view called @quoteCard and share it ? and I want just one view of my layout not want full screen screenshot. Thanks

<LinearLayout
        android:id="@+id/cardBackground"
        android:padding="8dp"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <de.hdodenhof.circleimageview.CircleImageView
            android:layout_marginTop="32dp"
            android:layout_gravity="center_horizontal"
            android:id="@+id/authorImage"
            android:layout_width="128dp"
            android:layout_height="128dp"
            app:civ_border_width="2dp"
            app:civ_border_color="#99333333"/>


        <TextView
            android:layout_weight="1"
            android:gravity="center"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:id="@+id/textDetailQuote"
            android:text="The price of success is hard"
            android:textSize="20sp"
            android:textStyle="bold"
            android:lineSpacingExtra="5dp"              
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


        <TextView
            android:layout_marginBottom="16dp"
            android:layout_marginRight="8dp"
            android:id="@+id/textAuthorSign"
            android:layout_gravity="right"
            android:text="- ABJ Abdul Kalam"
            android:textStyle="italic"
            android:textSize="16sp"
            android:typeface="serif"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />



    </LinearLayout>
Rajubhai Rathod
  • 481
  • 2
  • 5
  • 14

2 Answers2

0

This method will take a screenshot of a given view:

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;
}

To get a correct bitmap, pass the view that you want to take a screenshot of with it's width and height. After that, you can do anything you need with created Drawable.

Marijan
  • 671
  • 7
  • 16
  • I have LinearLayout with two textView and one imageView, How can I do with my above located xml ? – Rajubhai Rathod Jun 20 '16 at 10:05
  • Pass your linear layout and its width and height to the method. Example: `Bitmap bitmap = loadBitmapFromView(mLayout, mLayout.getWidth(), mLayout.getHeight());` mLayout would be your LinearLayout you want to take screenshot of. – Marijan Jun 20 '16 at 10:09
0

you can try this for take particular layout screen shot

   LinearLayout mLinearLayout= (LinearLayout) findViewById(R.id.linearlayout);
            mLinearLayout.setDrawingCacheEnabled(true);
            Bitmap mBitmap = Bitmap.createBitmap(mainLayout.getDrawingCache());
            mLinearLayout.setDrawingCacheEnabled(false);

Using above you can convert layout to bitmap.

Sachin
  • 1,159
  • 9
  • 21