gpt4 book ai didi

java - 安卓、Java : Share a dialog

转载 作者:行者123 更新时间:2023-12-01 13:15:33 25 4
gpt4 key购买 nike

我有一个对话框,里面有一些 TextView 和 ImageView。现在我想通过分享 Intent 来分享这一点。这可能吗?我可以共享对话框或先将其转换为位图然后再共享吗?

最佳答案

您可以使用此方法。

public static Bitmap TakeBitmapFromDialog(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;
}

或只需使用这个即可。

 View v1 = view.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);

更新:

如果您不想使用它,请使用它。

Bitmap cs = null;
view.setDrawingCacheEnabled(true);
view.buildDrawingCache(true);
cs = Bitmap.createBitmap(view.getDrawingCache());
Canvas canvas = new Canvas(cs);
view.draw(canvas);
canvas.save();
view.setDrawingCacheEnabled(false);

如果您想共享该位图,您需要在媒体图像中插入,例如,

 String path = Images.Media.insertImage(getContentResolver(), cs,
"MyImage", null);
Uri file = Uri.parse(path);

现在分享,

 Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, file);
startActivity(Intent.createChooser(sharingIntent,
"Share image using"));

关于java - 安卓、Java : Share a dialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22501554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com