dab*_*ous 10 android photo save imageview
我有一个具有共享意图的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"));
}
}
Run Code Online (Sandbox Code Playgroud)
更新 好的,所以我明白了.现在我有了一个新问题,如何将此图像保存到新文件夹?
保存和加载时,首先需要获取系统的根路径。我就是这样做的。
File root = Environment.getExternalStorageDirectory();
File cachePath = new File(root.getAbsolutePath() + "/DCIM/Camera/image.jpg");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13932 次 |
最近记录: |