Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 获取R.drawable ID';在安卓系统中,它是动态的_Android_Resources_Android Image - Fatal编程技术网

Android 获取R.drawable ID';在安卓系统中,它是动态的

Android 获取R.drawable ID';在安卓系统中,它是动态的,android,resources,android-image,Android,Resources,Android Image,我有一个文件夹和一些图像,这些图像是由用户动态添加的。所以我需要在android中获取这些图像的R.drawable ID 这些图像也保存在哪里?在运行时动态添加图像时,通常需要将其存储在手机存储器中。如果希望将图像存储在外部存储器(SD卡)中,则可以使用以下代码检索图像并将其添加到视图中(我假设您这样做)。此代码假定图像存储在设备SD卡中,从SD卡中提取图像 //Get root directory of storage directory, pass in the name of the F

我有一个文件夹和一些图像,这些图像是由用户动态添加的。所以我需要在android中获取这些图像的R.drawable ID

这些图像也保存在哪里?在运行时动态添加图像时,通常需要将其存储在手机存储器中。如果希望将图像存储在外部存储器(SD卡)中,则可以使用以下代码检索图像并将其添加到视图中(我假设您这样做)。此代码假定图像存储在设备SD卡中,从SD卡中提取图像

//Get root directory of storage directory, pass in the name of the Folder if they are      being stored farther down, i.e getExternalFilesDir("FolderName/FolderName2")

String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media


File dir = getExternalFilesDir(null);
    Bitmap bmap = null;
    try {
        InputStream is = new FileInputStream(new File(dir,"image.jpg"));
        bmap = BitmapFactory.decodeStream(is);
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    if (bmap!=null) {
        ImageView view = new ImageView(this);
        view.setImageBitmap(bmap);
    }
}

用户正在将图像放置在文件夹中,但我需要获取图像视图中图像的R.drawable.ID出于运气,任何动态添加的内容在编译后都不会转换为R.drawable.ID。