从名为 "images" 的示例文件目录加载文件
Load file from Sample File Directory named "images"
我有这个简单的结构
现在我应该从 URI 将 11.png
加载到 ImageView。
我该怎么做?
imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageURI(Uri.fromFile(new File("What should be here???")));
我认为你是 Android 的新手?
最好将图像文件移动到 Drawable 文件夹并从 Drawable 设置图像视图。您可以在 Android Studio 中使用 BatchDrawableImport 插件导入多个 Drawable 文件
imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.yourImageName);
或者将文件移动到 Assets 文件夹并使用 Assets Manager 您可以实现解决方案
AssetManager manager = getAssets();
// Read a Bitmap from Assets
try {
InputStream open = manager.open("icon.png");
Bitmap bitmap = BitmapFactory.decodeStream(open);
ImageView view = (ImageView) findViewById(R.id.ImageView01);
view.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
我有这个简单的结构
现在我应该从 URI 将 11.png
加载到 ImageView。
我该怎么做?
imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageURI(Uri.fromFile(new File("What should be here???")));
我认为你是 Android 的新手?
最好将图像文件移动到 Drawable 文件夹并从 Drawable 设置图像视图。您可以在 Android Studio 中使用 BatchDrawableImport 插件导入多个 Drawable 文件
imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.yourImageName);
或者将文件移动到 Assets 文件夹并使用 Assets Manager 您可以实现解决方案
AssetManager manager = getAssets();
// Read a Bitmap from Assets
try {
InputStream open = manager.open("icon.png");
Bitmap bitmap = BitmapFactory.decodeStream(open);
ImageView view = (ImageView) findViewById(R.id.ImageView01);
view.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}