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>
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.