如何获取android中的drawable image路径?

How to get the drawable image path in android?

您好,我想在 android 中获取可绘制图像路径,然后我想创建一个文件?有人可以帮我吗?

所以,你想知道如何从可绘制资源中将图像保存到 sdcard。对吧?

首先从您的可绘制资源中获取位图,然后将位图作为图像保存在您需要的位置

Bitmap bitmap = BitmapFactory.decodeResource( getResources(), R.drawable.my_image);

可以使用以下方法检索 SD 卡的路径:

String extStorageDirectory = Environment.getExternalStorageDirectory().toString();

然后保存到sdcard

File file = new File(extStorageDirectory, "myimagefile.png");
FileOutputStream outStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();

不要忘记在清单文件中添加 android.permission.WRITE_EXTERNAL_STORAGE 权限。