简体   繁体   中英

Android share text as image to other apps

I'm trying to share text from my app as an image to other apps. So I want a user to tap share on some content, have the app generate an image from the text, and add that to a chooser intent. (For example, sharing text from Twitter as an image on Instagram). I'm just not sure how to generate an image from the text and hand it in the proper format to the chooser. Any help is great, thanks!

One way is to create a Bitmap object from your TextView , storing it on disk and then sharing that file. This is how you can capture a View as a Bitmap object (courtesy of this answer ):

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

The rest should be easy enough.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM