美文网首页
相册读取并显示工作的改良

相册读取并显示工作的改良

作者: JohnYuCN | 来源:发表于2019-11-03 21:54 被阅读0次

    本文是继相册读取+文件上传

    一、Glid的加入

    在build.gradle的dependicies中加入:

        annotationProcessor 'androidx.annotation:annotation:1.0.0'
        implementation ("com.github.bumptech.glide:glide:4.9.0") {
            exclude group: "com.android.support"
        }
        annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    

    二、修改handleSelect()方法

        //选择后照片的读取工作
        private void handleSelect(Intent intent) {
            Cursor cursor = null;
            Uri uri = intent.getData();
            cursor = getContentResolver().query(uri, null, null, null, null);
            if (cursor.moveToFirst()) {
                int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME);
                uploadFileName = cursor.getString(columnIndex);
            }
            //==============此部分进行了修改======================
            try {
                Glide.with(this).load(uri)
                        .fitCenter()
                        .into(photo);
    
            } catch (Exception e) {
                e.printStackTrace();
            }
            //=================================================
            cursor.close();
        }
    
    

    相关文章

      网友评论

          本文标题:相册读取并显示工作的改良

          本文链接:https://www.haomeiwen.com/subject/svilbctx.html