我需要在 Android 应用程序中获取可绘制图像的绝对路径或文件对象。有什么办法吗?
Drawable如下
context.getResources().getDrawable(R.drawable.back_button)
最佳答案
如果您的应用安装在 SD 卡上,请尝试此代码:
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 - 获取android可绘制图像的绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25758159/