如何在安卓中保存和共享位图



我有图像视图和共享按钮的活动,从数据库检索的图像

我想先保存图像,然后分享

一切都很顺利,图像保存在内部存储器中,它将共享,但是当其他应用程序运行时(如WhatsApp或消息传递),它说文件不支持

我已经手动将其他图像推送到 ddms,然后共享没有任何问题!O.o

我认为问题出在保存位图上,即使我从ddms中检查了保存的位图,看起来也不错

有我的代码:

  try {
        FileOutputStream out = new FileOutputStream(new File(getFilesDir(), "temp.png"));
        imageview.setImageBitmap(b1);
        b1.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
       }
       catch (Exception e) {}

分享方式

  private void initShareIntent(String type,String _text)
  {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(getFilesDir(), "temp.png")));
        shareIntent.setType("image/PNG");
        shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(Intent.createChooser(shareIntent, "send"));
  }

编辑此内容

shareIntent.setType("image/*");

对此

shareIntent.setType("image/png");

我认为它应该有效。让我知道它是否适合您!!

[编辑1]更改为png(而不是PNG),因为我认为案件在这里很重要。 大声笑

[EDIT2] 对于多个图像,请尝试此操作(由 GOOGLE :P 提供)

ArrayList<Uri> imageUris = new ArrayList<Uri>();
imageUris.add(imageUri1); // Add your image URIs here
imageUris.add(imageUri2);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share images to.."));

最新更新