【发布时间】:2011-11-24 08:21:48
【问题描述】:
我正在创建一个照片应用程序,用户可以在其中从图库中选择图像,并显示在应用程序中心的图像视图中。我将如何为 ImageView 创建共享意图?
更新 共享意图有效,但是无法共享图像,因为我无法将其保存到我选择的路径。下面是我的代码。有什么帮助吗?
public void taptoshare(View v)
{
View content = findViewById(R.id.myimage);
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
File file = new File("/DCIM/Camera/image.jpg");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
Intent shareIntent = new Intent(Intent.ACTION_SEND);
Uri phototUri = Uri.parse("/DCIM/Camera/image.jpg");
shareIntent.setData(phototUri);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, phototUri);
startActivity(Intent.createChooser(shareIntent, "Share Via"));
}
}
【问题讨论】:
-
你想分享图片还是从本地图库中挑选图片?
-
我想分享在 ImageView 中显示的图像(用户从图库中选择的照片)
标签: java android android-intent imageview share