AndroidでGlideを使用してローカルイメージをロードする方法
ローカル画像を Glide で読み込む手順は次のとおりです。
- build.gradleファイルにGlideの依存関係を追加する:
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
- コードでGlideを使ってローカル画像を読み込む。
ImageView imageView = findViewById(R.id.imageView); // 获取ImageView实例
Glide.with(this)
.load(R.drawable.image) // 通过资源ID加载本地图片
.into(imageView); // 将图片加载到ImageView中
R.drawable.imageはネイティブの画像リソースのIDで、imageViewは画像を表示するImageViewコントロールです。
ファイルオブジェクトは、ローカルファイルへのパスの指定のために使用することができます。
ImageView imageView = findViewById(R.id.imageView); // 获取ImageView实例
File file = new File("/path/to/image.jpg"); // 指定本地图片文件的路径
Glide.with(this)
.load(file) // 通过File对象加载本地图片
.into(imageView); // 将图片加载到ImageView中
ネイティブアプリで画像を読み込むには、ファイルを読み込むパーミッションを追加する必要があります。