如何从XML资源中的矢量图像检索位图
我正在从XML资源中读取矢量图像并在ImageView中显示它。没关系。 现在,我需要通过intent.putExtra将图像传递给一个Intent。 问题:如何将矢量XML转换为位图或从ImageView获取图像? 我试过.getDrawingCache(),.getDrawable,getImageMatrix等,但它不起作用。如何从XML资源中的矢量图像检索位图
试过这样:
String path = MediaStore.Images.Media.insertImage(getApplicationContext().getContentResolver(),
imgPrevisao.getDrawingCache(),
"Minha previsão",null);
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path)) ;
getApplicationContext().startActivity(Intent.createChooser(sharingIntent, "Share with"));
而且这样:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_TEXT, textoPrevisao);
intent.putExtra(Intent.EXTRA_STREAM, imgPrevisao.getDrawingCache());
intent.setType("image/*");
startActivity(intent);
TIA,
安德烈·科雷亚
的方法之一是使用MediaStore:
public static Uri getImageUri(Context context, Bitmap bmp) {
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), , "share_title",bmp ,null);
return Uri.parse(path);
}
比:
public static void shareImageViewContent(ImageView view) {
Bitmap bitmap = ((BitmapDrawable)view.getDrawable()).getBitmap();
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, getImageUri(bitmap)) ;
context.startActivity(Intent.createChooser(sharingIntent, "Share with"));
}
一个比较复杂的解决方案是使用FileProvider 学分:link,link,link
谢谢j2ko,我会试试看。我没有足够的声望来支持你的答案,对不起。 –
@AndréAranhanp,我很乐意提供帮助。但我想你可以将我的解决方案标记为回答 – j2ko
它不起作用。我仍在尝试。我会发布我尝试过的。 –
类似的东西应该工作。漂亮的标准操作来从图像视图中获取位图。 – greenapps
这个意图应该在你的应用程序中处理吗? – j2ko
greenapps,对不起,像什么?我是Android开发新手。 –