我正在嘗試使用以下代碼獲取歌曲的封面(專輯藝術(shù)):public static String getCoverArtPath(Context context, long androidAlbumId) { String path = null; Cursor c = context.getContentResolver().query( MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Audio.Albums.ALBUM_ART}, MediaStore.Audio.Albums._ID + "=?", new String[]{Long.toString(androidAlbumId)}, null); if (c != null) { if (c.moveToFirst()) { path = c.getString(0); } c.close(); } return path;}該方法返回圖像路徑的字符串,但該路徑指向非格式化文件。如何在ImageView上設(shè)置這個圖像?如果您知道除此方法之外的任何其他方法,請告訴我。
1 回答

POPMUISE
TA貢獻(xiàn)1765條經(jīng)驗 獲得超5個贊
您可以從路徑創(chuàng)建一個可繪制對象并設(shè)置它
Drawable drawable = Drawable.createFromPath(path_of_the_cover_art);
yourImageView.setImageDrawable(drawable);
或者創(chuàng)建一個文件:
File image = new File(path_of_the_cover_art);
if(image.exists()){
Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath());
yourImageView.setImageBitmap(bitmap);
}
只需確保您擁有 WRITE_STORAGE_PERMISSION 即可!
添加回答
舉報
0/150
提交
取消