我如何保存的ImageView作为图像? [英] How do I save an ImageView as an image?
本文介绍了我如何保存的ImageView作为图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个共享意图的ImageView的(它的伟大工程,使所有的应用程序,我可以将影像分享的),但是,我不能共享的照片,因为它在我的手机没有路径。我该如何去拯救ImageView的我的手机上?下面是我的code。
I have an ImageView with a share intent( which works great, brings up all the apps I can share the image with), however, I can not share the photo because it has no path on my phone. How do I go about saving the ImageView on my phone? Below is my code.
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"));
}
}
更新 好了,我理解了它。现在我有一个新的问题,我怎么会去拯救这个图片给新文件夹?
UPDATE Ok, so I figured it out. Now I have a new question, how would I go about saving this image to a new folder?
推荐答案
在保存和加载,你需要得到系统的根路径,第一个。这就是我想要做的。
When saving and loading, you need to get the root path of the system, first. This is how I'd do it.
File root = Environment.getExternalStorageDirectory();
File cachePath = new File(root.getAbsolutePath() + "/DCIM/Camera/image.jpg");
这篇关于我如何保存的ImageView作为图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文