【发布时间】:2012-01-05 22:47:38
【问题描述】:
我有一个带有共享意图的 ImageView(效果很好,显示了我可以共享图像的所有应用程序),但是,我无法共享照片,因为它在我的手机上没有路径。如何在手机上保存 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"));
}
}
更新 好的,所以我想通了。现在我有一个新问题,我将如何将此图像保存到新文件夹中?
【问题讨论】:
-
应该单独提出一个新问题,因为您不能为一个问题授予多个答案。但无论如何,File 有一个 mkdirs() 方法,可以用来确保指定的文件夹存在。
-
哦,好的,谢谢@AlbeyAmakiir!注意到以后的帖子!
标签: android save imageview photo