AndroidQ:从文件中加载图片
创始人
2024-10-09 17:01:40
0

在Android Q及更高版本中,为确保应用程序具有适当的权限,需要使用不同的方法从文件加载图像。下面是使用ContentResolver和ImageDecoder加载图像的示例代码:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
    ContentResolver contentResolver = getContentResolver();
    Uri uri = Uri.parse("file:///storage/emulated/0/my_image.jpg");

    ImageDecoder.Source source = ImageDecoder.createSource(contentResolver, uri);
    try {
        Bitmap bitmap = ImageDecoder.decodeBitmap(source);
        imageView.setImageBitmap(bitmap);
    } catch (IOException e) {
        e.printStackTrace();
    }
} else {
    File file = new File(Environment.getExternalStorageDirectory(), "my_image.jpg");
    Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
    imageView.setImageBitmap(bitmap);
}

请注意,此代码将检查设备上的Android版本,如果版本为Android Q或更高版本,则使用ContentResolver和ImageDecoder加载图像。否则,它将使用传统的方法从文件加载图像。

相关内容

热门资讯

关于透视!hhpoker破解工... 关于透视!hhpoker破解工具,wepoker透视脚本安卓,指南书教程(有挂透视)-哔哩哔哩1、上...
分享透视!pokerworld... 分享透视!pokerworld破解版下载,pokemmo脚本辅助器下载,妙招教程(有挂透视)-哔哩哔...
普及透视!pokerrrr2辅... 普及透视!pokerrrr2辅助,aapoker辅助软件合法吗,方针教程(有挂透明挂)-哔哩哔哩1、...
辅助透视!wejoker黑侠辅... 辅助透视!wejoker黑侠辅助器,佛手在线大菠萝智能辅助器,攻略教程(真的有挂)-哔哩哔哩佛手在线...
专业透视!大菠萝免费辅助,哈糖... 专业透视!大菠萝免费辅助,哈糖大菠萝开挂,攻略教程(有挂助手)-哔哩哔哩1、每一步都需要思考,不同水...
辅助透视!智星菠萝有挂吗,we... 辅助透视!智星菠萝有挂吗,wepoker透视脚本免费下载,模板教程(发现有挂)-哔哩哔哩1、进入到w...
关于透视!hhpoker有没有... 关于透视!hhpoker有没有作必弊挂,pokerworld辅助器,技法教程(有挂方略)-哔哩哔哩1...
必备透视!wpk透视工作室,f... 必备透视!wpk透视工作室,fishpoker透视,指南教程(有挂猫腻)-哔哩哔哩必备透视!wpk透...
教你透视!uupoker有透视... 教你透视!uupoker有透视吗,werplan辅助软件,方式教程(有挂助手)-哔哩哔哩1、用户打开...
辅助透视!epoker底牌透视... 辅助透视!epoker底牌透视,红龙poker辅助,大纲教程(有挂功能)-哔哩哔哩1、用户打开应用后...