如何在android中从可绘制路径为imageview和线性布局设置图像
我成功地将图像加载到线性布局,并从本地路径加载图像,如下代码所示如何在android中从可绘制路径为imageview和线性布局设置图像,android,android-layout,android-imageview,Android,Android Layout,Android Imageview,我成功地将图像加载到线性布局,并从本地路径加载图像,如下代码所示 ImageView imagePerson=(ImageView) findViewById(R.id.imgPerson); LinearLayout layoutID=(LinearLayout)findViewById(R.id.layoutID); imagePerson.setImageResource(R.drawable.image1); layoutID.setBackgroundR
ImageView imagePerson=(ImageView) findViewById(R.id.imgPerson);
LinearLayout layoutID=(LinearLayout)findViewById(R.id.layoutID);
imagePerson.setImageResource(R.drawable.image1);
layoutID.setBackgroundResource(R.drawable.layout1);
但是,我需要将这些图像的路径保存到文件中。因此,我无法使用上述代码将图像加载到imageview和linearlayout。与此相反,我想找到从路径加载图像的方法。你能帮我用android解决这个问题吗。这是我获取路径的代码
String pathPerson="drawable://" + R.drawable.imgPerson;
String pathID="drawable://" + R.drawable.layoutID;
提前感谢使用int-type保存可绘制id 例如
使用int-type保存可绘制id 例如 有些方法是:
String imageUri = "drawable://" + R.drawable.image;
其他途径:
Uri path = Uri.parse("android.resource://com.segf4ult.test/" + R.drawable.icon);
Uri otherPath = Uri.parse("android.resource://com.segf4ult.test/drawable/icon");
String path = path.toString();
String path = otherPath .toString();
可以从以下字符串路径创建可绘制文件:
String pathGet = "/path/to/file/myFile.jpg";
Drawable d = Drawable.createFromPath(pathGet);
谢谢有些方法是:
String imageUri = "drawable://" + R.drawable.image;
其他途径:
Uri path = Uri.parse("android.resource://com.segf4ult.test/" + R.drawable.icon);
Uri otherPath = Uri.parse("android.resource://com.segf4ult.test/drawable/icon");
String path = path.toString();
String path = otherPath .toString();
可以从以下字符串路径创建可绘制文件:
String pathGet = "/path/to/file/myFile.jpg";
Drawable d = Drawable.createFromPath(pathGet);
谢谢在路径中添加这样的内容
String pathPerson="wright your package name:drawable/" + R.drawable.imgPerson;
我认为这是解决您问题的有效方法。在路径中添加这样的内容
String pathPerson="wright your package name:drawable/" + R.drawable.imgPerson;
我认为这可以解决您的问题。首先,您必须使用此方法将数据保存到文件中 然后你可以用
Bitmap Bitmap=BitmapFactory.decodeFile(字符串路径名)代码>
请参阅首先,您必须使用此方法将数据保存到文件中
然后你可以用
Bitmap Bitmap=BitmapFactory.decodeFile(字符串路径名)代码>
请参阅您可以将可提取id保存为整数。您可以将可提取id保存为整数。否。我成功地保存了它。我想加载到图像/线性布局否。我成功地保存了它。我想加载到图像/线性布局