【问题标题】:how to save and share bitmap in android如何在android中保存和共享位图
【发布时间】:2014-02-13 11:51:53
【问题描述】:

我有图像查看和分享按钮的活动, 从数据库中检索到的图像

我想先保存图片再分享

一切正常,图像保存在内存中,它会分享,但是当其他应用程序运行(如whatsapp或消息传递)时,它说文件不支持

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

我认为问题出在保存位图上,即使我从 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"));
  }

【问题讨论】:

标签: android share


【解决方案1】:

编辑这个

shareIntent.setType("image/*");

到这里

shareIntent.setType("image/png");

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

[EDIT1] 更改为 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.."));

【讨论】:

  • 我认为这个案例在 mime 类型中很重要
  • 不,问题不是来自这里,我之前检查过所有事情,因为我很难过它保存了位图但它不共享,但是如果我手动更改位图,它就可以工作:|
猜你喜欢
  • 1970-01-01
  • 2012-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多