本文介绍了取得Android绘制的图像的绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要得到的绝对路径还是我绘制的图像的android应用File对象。有没有办法做到这一点?
I need to get the absolute path or the File object of my drawable image in android application. Is there any way to do this?
绘制对象是如下
context.getResources()。getDrawable(R.drawable.back_button)
context.getResources().getDrawable(R.drawable.back_button)
推荐答案
如果您的应用程序是在SD卡insalled尝试这个code:
If you app is insalled on sdcard try this code :
Bitmap bitMap = BitmapFactory.decodeResource(getResources(),R.id.img1);
File mFile1 = Environment.getExternalStorageDirectory();
String fileName ="img1.jpg";
File mFile2 = new File(mFile1,fileName);
try {
FileOutputStream outStream;
outStream = new FileOutputStream(mFile2);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.flush();
outStream.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String sdPath = mFile1.getAbsolutePath().toString()+"/"+fileName;
Log.i("hiya", "Your IMAGE ABSOLUTE PATH:-"+sdPath);
File temp=new File(sdPath);
if(!temp.exists()){
Log.e("file","no image file at location :"+sdPath);
}
这篇关于取得Android绘制的图像的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!