首页 > 解决方案 > KOTLIN:Glide 图像未从 Firebase-Storage 加载到片段中

问题描述

Glide 似乎没有从 Firebase-storage 中的指定路径加载图像。尽管我的代码没有错误并且图像上传没有错误,但我仍然没有在加载时获得更新的片段页面。

声明代码:

 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (requestCode == RC_SELECT_IMAGE && resultCode == Activity.RESULT_OK &&
            data != null && data.data != null
        ) {

            val selectedImagePath = data.data
            val selectedImageBmp = MediaStore.Images.Media
                .getBitmap(activity?.contentResolver, selectedImagePath)

            val outputStream = ByteArrayOutputStream()
            selectedImageBmp.compress(Bitmap.CompressFormat.JPEG, 90, outputStream)
            selectedImageBytes = outputStream.toByteArray()

            Glide.with(this)
                .load(selectedImageBytes)
                .into(imageView_profile_picture)

            pictureJustChanged = true
        }

    }



        override fun onStart() {
            super.onStart()
            FirestoreUtil.getCurrentUser { user ->
                if (this@HomeFragment.isVisible) {
                    edittextPersonname.setText(user.name)
                    editTextBio.setText(user.bio)
                    editTextTextEmailAddress.setText(user.email)
                    edittextage.setText(user.age)
                    if (!pictureJustChanged && user.profilePicturePath != null)

                        
                        Glide.with(this)
                            .load(StorageUtil.pathToReference(user.profilePicturePath))
                            .apply(RequestOptions()
                                .placeholder(R.drawable.ic_circle))
                            .into(imageView_profile_picture)

                }
            }
        }

以下是我的 Gradle 库包:

//滑行

 implementation 'com.github.bumptech.glide:glide:4.11.0'

    kapt 'com.github.bumptech.glide:compiler:4.11.0'

apply plugin: 'kotlin-kapt'

标签: androidkotlinandroid-fragmentsandroid-glide

解决方案


出于某种原因,Android Kotlin Glide v4 要求您在 gradle 项目中声明两次“应用插件”库,即

第一个例子:

第一份宣言

第二审:

第二次申报实例


推荐阅读