无法从路径创建位图

问题描述 投票:0回答:1

我的代码没有从我搜索过很多的路径创建位图,但是没有找到解决方案,这是我的代码

val bitmap=BitmapFactory.decodeFile(path)

它总是返回null,我也尝试过滑行,但无济于事

  Glide.with(requireActivity()).asBitmap().load(pictureFilePath)
            .apply(RequestOptions().override(50, 50))
            .listener(object  : RequestListener<Bitmap> {
                override fun onLoadFailed(e: GlideException?, model: Any?, target: com.bumptech.glide.request.target.Target<Bitmap>?, isFirstResource: Boolean): Boolean {
                    return false
                }

                override fun onResourceReady(bitmap: Bitmap, model: Any?, target: com.bumptech.glide.request.target.Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
                    val mybitmap= bitmap // this bitmap return null

                    return true
                }

            }).submit()

谁能在这件事上帮助我?我很讨厌这样做

android bitmap uri android-glide android-bitmap
1个回答
0
投票

使用此路径是您的本地路径,请确保路径正确

BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(path.getAbsolutePath(),bmOptions);
bitmap = Bitmap.createScaledBitmap(bitmap,parent.getWidth(),parent.getHeight(),true);
© www.soinside.com 2019 - 2024. All rights reserved.