【问题标题】:How can I share an imageview that is being displayed on the screen? [duplicate]如何共享屏幕上显示的图像视图? [复制]
【发布时间】:2017-05-09 19:41:17
【问题描述】:

一个疑问。 如何共享屏幕上显示的图像视图?

这是一个应用示例: http://www.mediafire.com/convkey/d5a3/l0b5eobtpdbeoenzg.jpg

每次在图像上单击新图像时,使用的资源都是一个数组,用于在 Drawable 文件夹中查找 ID。

谢谢!!!

【问题讨论】:

  • 在屏幕底部添加一个新按钮并将其命名为“共享”按钮并为其编写代码
  • 或者使用 Intents 分享图片
  • 我的问题的解决方案:pt.stackoverflow.com/questions/203703/… 谢谢!!!

标签: java android share


【解决方案1】:
Try this...Don't forget to give write storage permission in manifest 
and run time for API greater than marshmallow.
Bitmap bitmap= 
BitmapFactory.decodeResource(getResources(),R.drawable.xxxx);
String path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES)+"/LatestShare.jpg";
OutputStream out = null;
File file=new File(path);
try {
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
path=file.getPath();
Uri bmpUri = Uri.parse("file://"+path);
 Intent shareIntent = new Intent();
shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/jpg");
startActivity(Intent.createChooser(shareIntent,"Share with"));

【讨论】:

  • 感谢玛丽卡的回复。我指了指我的数组,但是当分享不拉图的时候,是黑色的背景,被告知分享失败。除了路径 R.drawable.xxxx 必须更改代码中的其他内容吗?谢谢。
  • 尝试在上面的答案中进行编辑:TypedArray imgs = getResources().obtainTypedArray(R.array.random_imgs);位图位图= BitmapFactory.decodeResource(getResources(),imgs.getResourceId(i, -1)); i 是您单击的数组位置,-1 是默认值。
  • Malika,再次感谢您的帮助。他呼唤意图,却没有出现影像,依旧是黑色的背景。我在具有 Cyanogen 系统的设备上模拟直接应用程序,这会影响结果吗?因为我尝试了不同的解决方案,但没有一个对我有用。它可以是我的设备吗?非常感谢。
  • 做这个改变:ByteArrayOutputStream bytes = new ByteArrayOutputStream();尝试 { out = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, 字节); out.write(bytes.toByteArray()); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace();} 并将保存的图像 jpg 格式更改为 png。
猜你喜欢
  • 1970-01-01
  • 2012-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多