获取android drawable图像的绝对路径

Gay*_*hka 2 android path drawable

我需要在android应用程序中获取我的drawable图像的绝对路径或File对象.有没有办法做到这一点?

Drawable如下

context.getResources().getDrawable(R.drawable.back_button)

KOT*_*IOS 7

如果您的应用程序已在sdcard上安装,请尝试以下代码:

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);
}
Run Code Online (Sandbox Code Playgroud)


Nik*_*rad 6

Uri path = Uri.parse("android.resource://com.nikhil.material/" + R.drawable.image);
Run Code Online (Sandbox Code Playgroud)

要么

Uri otherPath = Uri.parse("android.resource://com.nikhil.material/drawable/image");
Run Code Online (Sandbox Code Playgroud)

要么

Uri path = Uri.parse("android.resource://"+BuildConfig.APPLICATION_ID+"/" + R.drawable.image);
Run Code Online (Sandbox Code Playgroud)