我正在创建一个照片应用程序,用户从该图库中选择图像并将其显示在应用程序中心的图像视图中。我将如何去创建ImageView的共享意图?如何为ImageView创建共享意图?
UPDATE 分享意图正在工作,但是,图像无法共享,因为我无法将其保存到我选择的路径。以下是我的代码。任何帮助?
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中显示的图像(用户从图库中选择的一张照片) – dabious